-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdocs_test.go
96 lines (94 loc) · 1.88 KB
/
docs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package kuu
import (
"testing"
)
func TestMarshal(t *testing.T) {
doc := Doc{
Openapi: "3.0.1",
Info: DocInfo{
Title: "Humansa",
Description: "Humansa 模型默认RESTful接口文档",
Contact: DocInfoContact{
Email: "[email protected]",
},
Version: "1.0.0",
},
Servers: []DocServer{
{
Url: "https://humansa.hofo.co",
},
},
Tags: []DocTag{
{
Name: "Member",
Description: "会员资讯",
},
{
Name: "Address",
Description: "会员地址",
},
},
Paths: map[string]DocPathItems{
"/member": {
"post": DocPathItem{
Tags: []string{"Member"},
Summary: "新增会员资讯",
OperationID: "createMember",
RequestBody: DocPathRequestBody{
Required: true,
Description: "新增会员资讯信息",
Content: map[string]DocPathContentItem{
"application/json": {
Schema: DocPathSchema{
Ref: "#/components/schemas/Member",
},
},
},
},
Responses: map[int]DocPathResponse{
200: {
Description: "接口调用成功",
Content: map[string]DocPathContentItem{
"application/json": {
Schema: DocPathSchema{
Ref: "#/components/schemas/Member",
},
},
},
},
},
},
},
},
Components: DocComponent{
Schemas: map[string]DocComponentSchema{
"Member": {
Type: "object",
Properties: map[string]DocSchemaProperty{
"ID": {
Type: "integer",
},
"Avatar": {
Type: "string",
},
"IsPassChanged": {
Type: "boolean",
Default: false,
},
},
},
},
SecuritySchemes: map[string]DocSecurityScheme{
"api_key": {
Type: "apiKey",
Name: "api_key",
In: "header",
},
},
},
}
yml := doc.Marshal()
if len(yml) < 0 {
t.Error("文档生成失败")
}
}