add int64 dataType

This commit is contained in:
MaxToby 2021-01-03 16:10:42 +08:00
parent ec36bd4c17
commit 65c9afac77
7 changed files with 70 additions and 244 deletions

View File

@ -1,3 +1,3 @@
package example
//go:generate goctl api plugin -plugin goctl-swagger="swagger" -api user.api -dir .
//go:generate goctl api plugin -plugin goctl-swagger="swagger" -api test.api -dir .

View File

@ -1,226 +0,0 @@
{
"swagger": "2.0",
"info": {
"title": "",
"version": ""
},
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/api/user/:id": {
"get": {
"summary": "获取用户信息",
"operationId": "/api/user/:id",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/UserInfoReply"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UserInfoReq"
}
}
],
"tags": [
"user-api"
]
}
},
"/api/user/login": {
"post": {
"summary": "登录",
"operationId": "/api/user/login",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {}
}
],
"tags": [
"user-api"
]
}
},
"/api/user/register": {
"post": {
"summary": "注册",
"description": "注册一个用户",
"operationId": "/api/user/register",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {}
}
],
"tags": [
"user-api"
]
}
},
"/api/user/search": {
"get": {
"summary": "用户搜索",
"operationId": "/api/user/search",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/UserSearchReply"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/UserSearchReq"
}
}
],
"tags": [
"user-api"
]
}
},
"/user/ping": {
"get": {
"operationId": "/user/ping",
"responses": {
"200": {
"description": "A successful response.",
"schema": {}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {}
}
],
"tags": [
"greet"
]
}
}
},
"definitions": {
"LoginReq": {
"type": "object",
"properties": {
"Username": {
"type": "string"
},
"Password": {
"type": "string"
}
},
"title": "LoginReq"
},
"RegisterReq": {
"type": "object",
"properties": {
"Username": {
"type": "string"
},
"Password": {
"type": "string"
},
"Mobile": {
"type": "string"
}
},
"title": "RegisterReq"
},
"UserInfoReply": {
"type": "object",
"properties": {
"Name": {
"type": "string"
},
"Age": {
"type": "integer",
"format": "int32"
},
"Birthday": {
"type": "string"
},
"Description": {
"type": "string"
},
"Tag": {
"type": "array",
"items": {
"type": "string"
}
}
},
"title": "UserInfoReply"
},
"UserInfoReq": {
"type": "object",
"properties": {
"Id": {
"type": "string"
}
},
"title": "UserInfoReq"
},
"UserSearchReply": {
"type": "object",
"properties": {
"KeyWord": {
"type": "array",
"items": {
"$ref": "#/definitions/UserInfoReply"
}
}
},
"title": "UserSearchReply"
},
"UserSearchReq": {
"type": "object",
"properties": {
"KeyWord": {
"type": "string"
}
},
"title": "UserSearchReq"
}
}
}

49
example/test.api Normal file
View File

@ -0,0 +1,49 @@
info(
title: "小程序商城"
desc: "小程序商品首页"
version: "1.0"
)
type IndexResp struct {
NewList []NewList `json:"NewList"`
RandomList []RandomList `json:"Randomlist"`
BannerList []BannerList `json:"bannerlist"`
}
type NewList struct {
GoodsList
}
type RandomList struct {
GoodsList
}
type BannerList struct {
Image string `json:"image"`
Title string `json:"title"`
ID int64 `json:"id"`
}
type GoodsList {
GoodsID int64 `json:"goods_id"`
GoodsName string `json:"goods_name"`
CategoryID int64 `json:"category_id"`
Images string `json:"images"`
SpecType string `json:"spec_type"`
DeductStockType string `json:"deduct_stock_type"`
Content string `json:"content"`
SalesInitial int `json:"sales_initial"`
SalesActual int `json:"sales_actual"`
GoodsSort int `json:"goods_sort"`
DeliveryID int64 `json:"delivery_id"`
GoodsStatus string `json:"goods_status"`
IsDelete string `json:"is_delete"`
ImageFrist string `json:"ImageFrist"`
GoodsSales int `json:"goods_sales"`
}
service index-api {
@doc(
summary: "首页列表"
)
@server(
handler: IndexHandler
)
get /index/index returns (IndexResp)
}

View File

@ -75,5 +75,4 @@ service user-api {
service user-api {
@handler ping
get /user/ping
}
//goctl api plugin -plugin goctl-swagger -api user.api -dir .
}

View File

@ -21,6 +21,8 @@ var (
swaggerMapTypes = map[string]reflect.Kind{
"string": reflect.String,
"int": reflect.Int,
"int32": reflect.Int,
"int64": reflect.Int64,
"[]string": reflect.Slice,
"bool": reflect.Bool,
"struct": reflect.Struct,

View File

@ -45,21 +45,20 @@ func renderServiceRoutes(service spec.Service, groups []spec.Group, paths swagge
parameters := swaggerParametersObject{}
reqRef := fmt.Sprintf("#/definitions/%s", route.RequestType.Name)
if len(route.ResponseType.Name) < 1 {
reqRef = ""
}
var schema = swaggerSchemaObject{
schemaCore: schemaCore{
Ref: reqRef,
},
if len(route.RequestType.Name) > 0 {
var schema = swaggerSchemaObject{
schemaCore: schemaCore{
Ref: reqRef,
},
}
parameters = append(parameters, swaggerParameterObject{
Name: "body",
In: "body",
Required: true,
Schema: &schema,
})
}
parameters = append(parameters, swaggerParameterObject{
Name: "body",
In: "body",
Required: true,
Schema: &schema,
})
pathItemObject, ok := paths[path]
if !ok {
pathItemObject = swaggerPathItemObject{}
@ -186,10 +185,13 @@ func schemaOfField(member spec.Member) swaggerSchemaObject {
return ret
}
// https://swagger.io/specification/ Data Types
func primitiveSchema(kind reflect.Kind, t string) (ftype, format string, ok bool) {
switch kind {
case reflect.Int:
return "integer", "int32", true
case reflect.Int64:
return "integer", "int64", true
case reflect.Bool:
return "boolean", "boolean", true
case reflect.String:

View File

@ -10,9 +10,9 @@ import (
)
var (
version = "20210101"
version = "20210103"
commands = []*cli.Command{
{
{git add
Name: "swagger",
Usage: "generates swagger.json",
Action: action.Generator,