add int64 dataType
This commit is contained in:
parent
ec36bd4c17
commit
65c9afac77
@ -1,3 +1,3 @@
|
|||||||
package example
|
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 .
|
||||||
|
@ -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
49
example/test.api
Normal 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)
|
||||||
|
}
|
@ -75,5 +75,4 @@ service user-api {
|
|||||||
service user-api {
|
service user-api {
|
||||||
@handler ping
|
@handler ping
|
||||||
get /user/ping
|
get /user/ping
|
||||||
}
|
}
|
||||||
//goctl api plugin -plugin goctl-swagger -api user.api -dir .
|
|
@ -21,6 +21,8 @@ var (
|
|||||||
swaggerMapTypes = map[string]reflect.Kind{
|
swaggerMapTypes = map[string]reflect.Kind{
|
||||||
"string": reflect.String,
|
"string": reflect.String,
|
||||||
"int": reflect.Int,
|
"int": reflect.Int,
|
||||||
|
"int32": reflect.Int,
|
||||||
|
"int64": reflect.Int64,
|
||||||
"[]string": reflect.Slice,
|
"[]string": reflect.Slice,
|
||||||
"bool": reflect.Bool,
|
"bool": reflect.Bool,
|
||||||
"struct": reflect.Struct,
|
"struct": reflect.Struct,
|
||||||
|
@ -45,21 +45,20 @@ func renderServiceRoutes(service spec.Service, groups []spec.Group, paths swagge
|
|||||||
parameters := swaggerParametersObject{}
|
parameters := swaggerParametersObject{}
|
||||||
|
|
||||||
reqRef := fmt.Sprintf("#/definitions/%s", route.RequestType.Name)
|
reqRef := fmt.Sprintf("#/definitions/%s", route.RequestType.Name)
|
||||||
if len(route.ResponseType.Name) < 1 {
|
if len(route.RequestType.Name) > 0 {
|
||||||
reqRef = ""
|
var schema = swaggerSchemaObject{
|
||||||
}
|
schemaCore: schemaCore{
|
||||||
var schema = swaggerSchemaObject{
|
Ref: reqRef,
|
||||||
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]
|
pathItemObject, ok := paths[path]
|
||||||
if !ok {
|
if !ok {
|
||||||
pathItemObject = swaggerPathItemObject{}
|
pathItemObject = swaggerPathItemObject{}
|
||||||
@ -186,10 +185,13 @@ func schemaOfField(member spec.Member) swaggerSchemaObject {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://swagger.io/specification/ Data Types
|
||||||
func primitiveSchema(kind reflect.Kind, t string) (ftype, format string, ok bool) {
|
func primitiveSchema(kind reflect.Kind, t string) (ftype, format string, ok bool) {
|
||||||
switch kind {
|
switch kind {
|
||||||
case reflect.Int:
|
case reflect.Int:
|
||||||
return "integer", "int32", true
|
return "integer", "int32", true
|
||||||
|
case reflect.Int64:
|
||||||
|
return "integer", "int64", true
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
return "boolean", "boolean", true
|
return "boolean", "boolean", true
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
|
4
main.go
4
main.go
@ -10,9 +10,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "20210101"
|
version = "20210103"
|
||||||
commands = []*cli.Command{
|
commands = []*cli.Command{
|
||||||
{
|
{git add
|
||||||
Name: "swagger",
|
Name: "swagger",
|
||||||
Usage: "generates swagger.json",
|
Usage: "generates swagger.json",
|
||||||
Action: action.Generator,
|
Action: action.Generator,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user