Skip to content

Commit 4e3f6b6

Browse files
committed
feat: response map
1 parent d5e700e commit 4e3f6b6

File tree

7 files changed

+210
-118
lines changed

7 files changed

+210
-118
lines changed

.vscode/launch.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Launch file",
9+
"type": "go",
10+
"request": "launch",
11+
"mode": "debug",
12+
"program": "${workspaceFolder}/cmd/apidoc/main.go"
13+
}
14+
]
15+
}

examples/docs/apis-greeter.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,31 @@ GET /greeter
1919
{ //object(main.Response), 通用返回结果
2020
"code": 0, //int, 返回状态码
2121
"data": { //object(main.TestData)
22-
"MyInt": 123, //int
22+
"Map2": { //object(main.TestData2)
23+
"abc": null //object
24+
},
25+
"Map3": { //object(main.TestData2)
26+
"abc": { //object(main.TestData2)
27+
"MyAge2": 123, //int
28+
"MyTitle2": "abc" //string, 标题2
29+
}
30+
},
2331
"MyInts": [ //array[int]
2432
123
25-
]
33+
],
34+
"Nodes": { //object(main.Node)
35+
"abc": { //object(main.Node)
36+
"Name": "abc", //string
37+
"Nodes": { //object(main.Node)
38+
"abc": null //object
39+
}
40+
}
41+
},
42+
"amap": , //object
43+
"data2": { //object(main.TestData2)
44+
"MyAge2": 123, //int
45+
"MyTitle2": "abc" //string, 标题2
46+
}
2647
},
2748
"msg": "返回消息" //string, 返回文本消息
2849
}

examples/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,27 @@ type TestData2 struct {
3232
MyTitle2 string //标题2
3333
MyAge2 int
3434
}
35+
type Map map[string]interface{}
36+
type Map2 map[string]TestData2
37+
type Node struct {
38+
Name string
39+
Nodes map[string]Node
40+
}
3541
type TestData struct {
3642
// MyTitle string `json:"my_title,omitempty"` //标题
37-
// Data2 *TestData2 `json:"data2,omitempty"`
43+
Data2 *TestData2 `json:"data2,omitempty"`
3844
// MyIntData int
3945
// MyFloat64 float64
4046
// MyFloat32 float32
4147
// MyIntArray []int
4248
// MyTestData2Array []TestData2
4349
// Int *int
44-
MyInt MyInt
50+
// MyInt MyInt
4551
MyInts []MyInt
52+
Map Map `json:"amap"`
53+
Map2 Map2
54+
Map3 map[string]TestData2
55+
Nodes map[string]Node
4656
}
4757

4858
type Request struct {

operation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (operation *Operation) ParseRequestComment(commentLine string, astFile *ast
127127
case IsGolangPrimitiveType(refType):
128128
return nil
129129
default:
130-
schema, err := operation.parser.getTypeSchema(refType, astFile, nil, true)
130+
schema, err := operation.parser.getTypeSchema(refType, astFile, nil)
131131
if err != nil {
132132
return err
133133
}
@@ -205,7 +205,7 @@ func (operation *Operation) parseObject(refType string, astFile *ast.File) (*Typ
205205
case strings.Contains(refType, "{"):
206206
return operation.parseCombinedObject(refType, astFile)
207207
default:
208-
schema, err := operation.parser.getTypeSchema(refType, astFile, nil, true)
208+
schema, err := operation.parser.getTypeSchema(refType, astFile, nil)
209209
if err != nil {
210210
return nil, err
211211
}

0 commit comments

Comments
 (0)