-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmodels.go
178 lines (141 loc) · 4.24 KB
/
models.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package docs
func New() OAS {
initRoutes := RegRoutes{}
return OAS{
RegisteredRoutes: initRoutes,
}
}
const (
OASAnnotationInit = "// @OAS "
)
// OAS - represents Open API Specification structure, in its approximated Go form.
type OAS struct {
OASVersion OASVersion `yaml:"openapi"`
Info Info `yaml:"info"`
ExternalDocs ExternalDocs `yaml:"externalDocs"`
Servers Servers `yaml:"servers"`
Tags Tags `yaml:"tags"`
Paths Paths `yaml:"paths"`
Components Components `yaml:"components"`
RegisteredRoutes RegRoutes `yaml:"-"`
}
// Version is represented in SemVer format.
type (
Version string
URL string
OASVersion Version
)
type Info struct {
Title string `yaml:"title"`
Description string `yaml:"description"`
TermsOfService URL `yaml:"termsOfService"`
Contact Contact `yaml:"contact"`
License License `yaml:"license"`
Version Version `yaml:"version"`
}
type Contact struct {
Email string `yaml:"email"`
}
type License struct {
Name string `yaml:"name"`
URL URL `yaml:"url"`
}
type ExternalDocs struct {
Description string `yaml:"description"`
URL URL `yaml:"url"`
}
type Servers []Server
type Server struct {
URL URL `yaml:"url"`
}
type Tags []Tag
type Tag struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
ExternalDocs ExternalDocs `yaml:"externalDocs"`
}
type Paths []Path
type Path struct {
Route string `yaml:"route"`
HTTPMethod string `yaml:"httpMethod"`
Tags []string `yaml:"tags"`
Summary string `yaml:"summary"`
OperationID string `yaml:"operationId"`
RequestBody RequestBody `yaml:"requestBody"`
Responses Responses `yaml:"responses"`
Security SecurityEntities `yaml:"security,omitempty"`
HandlerFuncName string `yaml:"-"`
}
type RequestBody struct {
Description string `yaml:"description"`
Content ContentTypes `yaml:"content"`
Required bool `yaml:"required"`
}
type ContentTypes []ContentType
type ContentType struct {
Name string `yaml:"ct-name"` // e.g. application/json
Schema string `yaml:"ct-schema"` // e.g. $ref: '#/components/schemas/Pet'
}
type Responses []Response
type Response struct {
Code uint `yaml:"code"`
Description string `yaml:"description"`
Content ContentTypes `yaml:"content"`
}
type SecurityEntities []Security
type Security struct {
AuthName string
PermTypes []string // write:pets , read:pets etc.
}
type Components []Component
type Component struct {
Schemas Schemas `yaml:"schemas"`
SecuritySchemes SecuritySchemes `yaml:"securitySchemes"`
}
type Schemas []Schema
type Schema struct {
Name string
Type string
Properties SchemaProperties
XML XMLEntry `yaml:"xml, omitempty"`
Ref string // $ref: '#/components/schemas/Pet' // TODO: Should this be omitted if empty?
}
type XMLEntry struct {
Name string
}
type SchemaProperties []SchemaProperty
type SchemaProperty struct {
Name string `yaml:"-"`
Type string // OAS3.0 data types - e.g. integer, boolean, string
Format string `yaml:"format,omitempty"`
Description string `yaml:"description,omitempty"`
Enum []string `yaml:"enum,omitempty"`
Default interface{} `yaml:"default,omitempty"`
}
type SecuritySchemes []SecurityScheme
type SecurityScheme struct {
Name string `yaml:"name,omitempty"`
Type string `yaml:"type,omitempty"`
In string `yaml:"in,omitempty"`
Flows SecurityFlows `yaml:"flows,omitempty"`
}
type SecurityFlows []SecurityFlow
type SecurityFlow struct {
Type string `yaml:"type,omitempty"`
AuthURL URL `yaml:"authorizationUrl,omitempty"`
Scopes SecurityScopes `yaml:"scopes,omitempty"`
}
type SecurityScopes []SecurityScope
type SecurityScope struct {
Name string `yaml:"name,omitempty"`
Description string `yaml:"description,omitempty"`
}
func (ed *ExternalDocs) isEmpty() bool {
if ed == nil {
return true
}
if ed.Description == emptyStr && ed.URL == emptyStr {
return true
}
return false
}