Skip to content

Commit

Permalink
feat: response map
Browse files Browse the repository at this point in the history
  • Loading branch information
alovn committed May 9, 2022
1 parent d5e700e commit 4e3f6b6
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 118 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/apidoc/main.go"
}
]
}
25 changes: 23 additions & 2 deletions examples/docs/apis-greeter.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,31 @@ GET /greeter
{ //object(main.Response), 通用返回结果
"code": 0, //int, 返回状态码
"data": { //object(main.TestData)
"MyInt": 123, //int
"Map2": { //object(main.TestData2)
"abc": null //object
},
"Map3": { //object(main.TestData2)
"abc": { //object(main.TestData2)
"MyAge2": 123, //int
"MyTitle2": "abc" //string, 标题2
}
},
"MyInts": [ //array[int]
123
]
],
"Nodes": { //object(main.Node)
"abc": { //object(main.Node)
"Name": "abc", //string
"Nodes": { //object(main.Node)
"abc": null //object
}
}
},
"amap": , //object
"data2": { //object(main.TestData2)
"MyAge2": 123, //int
"MyTitle2": "abc" //string, 标题2
}
},
"msg": "返回消息" //string, 返回文本消息
}
Expand Down
14 changes: 12 additions & 2 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,27 @@ type TestData2 struct {
MyTitle2 string //标题2
MyAge2 int
}
type Map map[string]interface{}
type Map2 map[string]TestData2
type Node struct {
Name string
Nodes map[string]Node
}
type TestData struct {
// MyTitle string `json:"my_title,omitempty"` //标题
// Data2 *TestData2 `json:"data2,omitempty"`
Data2 *TestData2 `json:"data2,omitempty"`
// MyIntData int
// MyFloat64 float64
// MyFloat32 float32
// MyIntArray []int
// MyTestData2Array []TestData2
// Int *int
MyInt MyInt
// MyInt MyInt
MyInts []MyInt
Map Map `json:"amap"`
Map2 Map2
Map3 map[string]TestData2
Nodes map[string]Node
}

type Request struct {
Expand Down
4 changes: 2 additions & 2 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (operation *Operation) ParseRequestComment(commentLine string, astFile *ast
case IsGolangPrimitiveType(refType):
return nil
default:
schema, err := operation.parser.getTypeSchema(refType, astFile, nil, true)
schema, err := operation.parser.getTypeSchema(refType, astFile, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (operation *Operation) parseObject(refType string, astFile *ast.File) (*Typ
case strings.Contains(refType, "{"):
return operation.parseCombinedObject(refType, astFile)
default:
schema, err := operation.parser.getTypeSchema(refType, astFile, nil, true)
schema, err := operation.parser.getTypeSchema(refType, astFile, nil)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 4e3f6b6

Please sign in to comment.