/
types.go
330 lines (291 loc) · 15.2 KB
/
types.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
package swagger
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"github.com/Azure/ARO-RP/pkg/util/orderedmap"
)
// Swagger represents a Swagger object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#swagger-object
type Swagger struct {
Swagger string `json:"swagger,omitempty"`
Info *Info `json:"info,omitempty"`
Host string `json:"host,omitempty"`
BasePath string `json:"basePath,omitempty"`
Schemes []string `json:"schemes,omitempty"`
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
Paths Paths `json:"paths,omitempty"`
Definitions Definitions `json:"definitions,omitempty"`
Parameters ParametersDefinitions `json:"parameters,omitempty"`
Responses ResponsesDefinitions `json:"responses,omitempty"`
SecurityDefinitions SecurityDefinitions `json:"securityDefinitions,omitempty"`
Security []SecurityRequirement `json:"security,omitempty"`
Tags []*Tag `json:"tags,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
}
// Info represents an Info object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#info-object
type Info struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
TermsOfService string `json:"termsOfService,omitempty"`
Contact *Contact `json:"contact,omitempty"`
License *License `json:"license,omitempty"`
Version string `json:"version,omitempty"`
}
// Contact represents a Contact object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#contact-object
type Contact struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
}
// License represents a License object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#license-object
type License struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
}
// Paths represents a Paths object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#paths-object
type Paths map[string]*PathItem
// PathItem represents a Path Item object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#path-item-object
type PathItem struct {
Ref string `json:"$ref,omitempty"`
Get *Operation `json:"get,omitempty"`
Put *Operation `json:"put,omitempty"`
Post *Operation `json:"post,omitempty"`
Delete *Operation `json:"delete,omitempty"`
Options *Operation `json:"options,omitempty"`
Head *Operation `json:"head,omitempty"`
Patch *Operation `json:"patch,omitempty"`
Parameters []interface{} `json:"parameters,omitempty"`
}
// Operation represents an Operation object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#operation-object
type Operation struct {
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
OperationID string `json:"operationId,omitempty"`
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
Parameters []interface{} `json:"parameters,omitempty"`
Responses Responses `json:"responses,omitempty"`
Schemes []string `json:"schemes,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
LongRunningOperation bool `json:"x-ms-long-running-operation,omitempty"`
Examples map[string]Reference `json:"x-ms-examples,omitempty"`
}
// ExternalDocumentation represents an External Documentation object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#external-documentation-object
type ExternalDocumentation struct {
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
}
// Parameter represents a Parameter object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object
type Parameter struct {
Name string `json:"name,omitempty"`
In string `json:"in,omitempty"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Schema *Schema `json:"schema,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
AllowEmptyValue bool `json:"allowEmptyValue,omitempty"`
Items *Items `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"`
Default interface{} `json:"default,omitempty"`
Maximum int `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum int `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
MinLength int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems int `json:"maxItems,omitempty"`
MinItems int `json:"minItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
MultipleOf int `json:"multipleOf,omitempty"`
}
// Items represents an Items object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#items-object
type Items struct {
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Items *Items `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"`
Default interface{} `json:"default,omitempty"`
Maximum int `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum int `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
MinLength int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems int `json:"maxItems,omitempty"`
MinItems int `json:"minItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
MultipleOf int `json:"multipleOf,omitempty"`
}
// Responses represents a Responses object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responses-object
type Responses map[string]interface{}
// Response represents a Response object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#response-object
type Response struct {
Description string `json:"description,omitempty"`
Schema *Schema `json:"schema,omitempty"`
Headers Headers `json:"headers,omitempty"`
Examples Example `json:"examples,omitempty"`
}
// Headers represents a Headers object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#headers-object
type Headers map[string]*Header
// Example represents an Example object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#example-object
type Example map[string]interface{}
// Header represents a Header object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#header-object
type Header struct {
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Items *Items `json:"items,omitempty"`
CollectionFormat string `json:"collectionFormat,omitempty"`
Default interface{} `json:"default,omitempty"`
Maximum int `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum int `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
MinLength int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems int `json:"maxItems,omitempty"`
MinItems int `json:"minItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
MultipleOf int `json:"multipleOf,omitempty"`
}
// Tag represents a Tag object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#tag-object
type Tag struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
}
// Reference represents a Reference object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#reference-object
type Reference struct {
Ref string `json:"$ref,omitempty"`
}
// Schema represents a Schema object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#schema-object
type Schema struct {
Ref string `json:"$ref,omitempty"`
Format string `json:"format,omitempty"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Default interface{} `json:"default,omitempty"`
MultipleOf int `json:"multipleOf,omitempty"`
Maximum int `json:"maximum,omitempty"`
ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"`
Minimum int `json:"minimum,omitempty"`
ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"`
MaxLength int `json:"maxLength,omitempty"`
MinLength int `json:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty"`
MaxItems int `json:"maxItems,omitempty"`
MinItems int `json:"minItems,omitempty"`
UniqueItems bool `json:"uniqueItems,omitempty"`
MaxProperties int `json:"maxProperties,omitempty"`
MinProperties int `json:"minProperties,omitempty"`
Required bool `json:"required,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Type string `json:"type,omitempty"`
Items *Schema `json:"items,omitempty"`
AllOf []Schema `json:"allOf,omitempty"`
Properties NameSchemas `json:"properties,omitempty"`
AdditionalProperties *Schema `json:"additionalProperties,omitempty"`
Discriminator string `json:"discriminator,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
XML *XML `json:"xml,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
Example interface{} `json:"example,omitempty"`
ClientFlatten bool `json:"x-ms-client-flatten,omitempty"`
Mutability []string `json:"x-ms-mutability,omitempty"`
}
// XML represents an XML object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#xml-object
type XML struct {
Description string `json:"description,omitempty"`
URL string `json:"url,omitempty"`
}
// Definitions represents a Definitions object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#definitions-object
type Definitions map[string]*Schema
// ParametersDefinitions represents a Parameters Definitions object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameters-definitions-object
type ParametersDefinitions map[string]*Parameter
// ResponsesDefinitions represents a Responses Definitions object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responses-definitions-object
type ResponsesDefinitions map[string]*Response
// SecurityDefinitions represents a Security Definitions object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-definitions-object
type SecurityDefinitions map[string]*SecurityScheme
// SecurityScheme represents a Security Scheme object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-scheme-object
type SecurityScheme struct {
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
In string `json:"in,omitempty"`
Flow string `json:"flow,omitempty"`
AuthorizationURL string `json:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty"`
Scopes Scopes `json:"scopes,omitempty"`
}
// Scopes represents a Scopes object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#scopes-object
type Scopes map[string]string
// SecurityRequirement represents a Security Requirement object
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-requirement-object
type SecurityRequirement map[string][]string
// from here downwards the types don't match the Swagger specification:
// NameSchemas uses orderedmap to ensure that the ordering of properties stanzas
// is respected.
// NameParameters is a slice of NameParameters
type NameParameters []NameParameter
// NameParameter representes a name and a Parameter
type NameParameter struct {
Name string
Parameter interface{}
}
// UnmarshalJSON implements json.Unmarshaler
func (xs *NameParameters) UnmarshalJSON(b []byte) error {
return orderedmap.UnmarshalJSON(b, xs)
}
// MarshalJSON implements json.Marshaler
func (xs NameParameters) MarshalJSON() ([]byte, error) {
return orderedmap.MarshalJSON(xs)
}
// NameSchemas is a slice of NameSchemas
type NameSchemas []NameSchema
// NameSchema represents a name and a Schema
type NameSchema struct {
Name string
Schema *Schema
}
// UnmarshalJSON implements json.Unmarshaler
func (xs *NameSchemas) UnmarshalJSON(b []byte) error {
return orderedmap.UnmarshalJSON(b, xs)
}
// MarshalJSON implements json.Marshaler
func (xs NameSchemas) MarshalJSON() ([]byte, error) {
return orderedmap.MarshalJSON(xs)
}