-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathjson-schema-cheatsheet.yml
320 lines (317 loc) · 9.77 KB
/
json-schema-cheatsheet.yml
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
swagger: "2.0"
info:
title: go-swagger JSON Schema support cheatsheet
version: 1.1.0
consumes:
- application/json
produces:
- application/json
schemes:
- https
host: localhost
paths:
/v0.19.0/json-schema:
post:
summary: JSON Schema support
parameters:
- name: cheatsheet
in: body
required: true
schema:
$ref: '#/definitions/JSONSchema-v0.19.0'
responses:
default: {$ref: '#/responses/Error'}
responses:
# Return general errors using same model as used by go-swagger for validation errors.
Error:
description: Error
schema:
$ref: '#/definitions/Error'
definitions:
# This model should match output of api.ServeError handler, to ensure
# errors returned by go-swagger (like failed validation) use same
# format as general errors returned by our handlers.
# By default api.ServeError = github.com/go-openapi/errors.ServeError.
Error:
type: object
required:
- code
- message
properties:
code:
description: Either same as HTTP Status Code OR >= 600 with HTTP Status Code 422
type: integer
format: int32
message:
type: string
### List of all available validations/annotations.
#
# x-go-name: "string" # give explicit type name to the generated model
# x-go-custom-tag: "string" # add serialization tags to an object property
# x-nullable: true|false # accepts null values (i.e. rendered as a pointer)
# x-is-nullable: true|false # same as x-nullable
# x-go-type: "string" # explicitly reuse an already available go type
# x-class: "string" # give explicit polymorphic class name in discriminator
# x-order: number # indicates explicit generation ordering for schemas (e.g. models, properties, allOf, ...)
#
# While validating body with JSON only listed below and NOT COMMENTED
# keywords actually works. Keywords commented XXX works partially.
JSONSchema-v0.19.0:
type: object
properties:
# PI:
# const: 3.14 # draft-06
# color:
# enum: ["RED", "GREEN", "BLUE"]
# nothing:
# type: null # not in Swagger 2.0, replace with x-nullable:
flag:
type: boolean
# flag_or_list:
# type:
# - boolean
# - array
name:
type: string
maxLength: 10
minLength: 3
pattern: '^go.regexp$' # XXX instead of ECMA 262 '^abc[abc-z][^a-z]a?a+a*a??a+?a*?a{3}a{1,3}a{3,}a{1,3}?a{3,}?(a|b)$'
enum: ["ONE", "TWO"]
count:
type: integer
minimum: 1
exclusiveMinimum: true # draft-06: change type to number instead of bool
maximum: 10
exclusiveMaximum: true # draft-06: change type to number instead of bool
multipleOf: 2
enum: [10, 20]
price:
type: number
minimum: 1.23
exclusiveMinimum: true # draft-06: change type to number instead of bool
maximum: 3.14
exclusiveMaximum: true # draft-06: change type to number instead of bool
multipleOf: 2
enum: [1.1, 2.2]
list_of_same_type:
type: array
minItems: 1
maxItems: 5
uniqueItems: true
items:
type: string
enum: [["abc", "xyz"], ["123", "789"]]
# contains:
list:
type: array
# minItems: 1
# maxItems: 5
# uniqueItems: true
items: # don't work in Swagger Editor 3.22.1
- type: string # XXX incomplete tuples and tuples with array validation are not properly validated
- type: number
- type: number
# contains: # draft-06
additionalItems: # XXX require --skip-validation
- type: integer
enum: [["one", 1, 10], ["two", 2.2, 20.2, 22]]
list_printf_args:
type: array
items: # don't work in Swagger Editor 3.22.1
- type: string
additionalItems: true # XXX require --skip-validation, false not working
enum: [["one"], ["two", 1, 2.2, "last"]]
map:
type: object
# minProperties: 2
# maxProperties: 10
required: # keys must exists, but may have empty values
- key
# - additional_key
properties:
name:
type: string
key:
type: string
additionalProperties: # everything not listed in properties or patternProperties
type: string
enum: [{"key":""}, {"key":"one", "name":"two"}]
# patternProperties:
# dependencies:
# propertyNames: # draft-06
# if: # draft-07
# then: # draft-07
# else: # draft-07
map2:
type: object
properties:
key:
type: string
additionalProperties: true # XXX false not working; don't work in Swagger Editor 3.22.1
enum: [{}, {"key":"one", "extra":"two"}]
# anyOf:
# oneOf:
# not:
subClass1or2:
$ref: '#/definitions/BaseClass'
formats:
type: object
properties:
num1:
type: integer
format: int32
num1u:
type: integer
format: uint32
num2:
type: integer
format: int64
num2u:
type: integer
format: uint64
num3:
type: number
format: float
num4:
type: number
format: double
bin1:
type: string
format: byte # base64-encoded string
bin2:
type: string
format: binary # octets
key0:
type: string
format: password
key1:
type: string
format: date-time # 2006-01-02T15:04:05Z
key2:
type: string
format: date # 2006-01-02
# key3:
# type: string
# format: time # draft-07, 15:04:05Z07:00
key4:
type: string
format: email
# key4idn:
# type: string
# format: idn-email # draft-07
key5:
type: string
format: hostname
# key5idn:
# type: string
# format: idn-hostname # draft-07
key6:
type: string
format: ipv4
key7:
type: string
format: ipv6
key8:
type: string
format: uri
# key8ref:
# type: string
# format: uri-reference # draft-06
# key8i:
# type: string
# format: iri # draft-07
# key8iref:
# type: string
# format: iri-reference # draft-07
# key9:
# type: string
# format: uri-template # draft-06
# key10:
# type: string
# format: json-pointer # draft-06
# key10rel:
# type: string
# format: relative-json-pointer # draft-07
# key11:
# type: string
# format: regex # draft-07
strfmt1:
type: string
format: bsonobjectid
strfmt2:
type: string
format: creditcard
strfmt3:
type: string
format: duration # "3 weeks", "1ms"
strfmt4:
type: string
format: hexcolor # "#FFFFFF"
strfmt5:
type: string
format: isbn
strfmt6:
type: string
format: isbn10
strfmt7:
type: string
format: isbn13
strfmt8:
type: string
format: mac # "01:02:03:04:05:06"
strfmt9:
type: string
format: rgbcolor # "rgb(100,100,100)"
strfmt10:
type: string
format: ssn
strfmt11:
type: string
format: uuid
strfmt12:
type: string
format: uuid3
strfmt13:
type: string
format: uuid4
strfmt14:
type: string
format: uuid5
# strfmt15:
# type: string
# format: cidr # "192.0.2.1/24", "2001:db8:a0b:12f0::1/32"
# key:
# type: string
# contentEncoding: base64 # draft-07
# contentMediaType: image/png # draft-07
annotations:
type: string
title: Title
description: Description
default: Unknown # force nullable, but doesn't use this value
readOnly: true # draft-07, validation not supported
# writeOnly: true # draft-07
# examples: # draft-06
example: Something # OpenAPI 2
BaseClass:
type: object
discriminator: kind
required:
- kind
properties:
kind:
type: string
SubClass1: # kind="SubClass1"
allOf:
- $ref: '#/definitions/BaseClass'
- type: object
properties:
something:
type: string
SubClass2: # kind="SubClass2"
allOf:
- $ref: '#/definitions/BaseClass'
- type: object
properties:
otherthing:
type: number