json_schemer 1.0.3 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +2 -7
  3. data/CHANGELOG.md +51 -0
  4. data/Gemfile.lock +10 -3
  5. data/README.md +328 -14
  6. data/json_schemer.gemspec +3 -1
  7. data/lib/json_schemer/content.rb +18 -0
  8. data/lib/json_schemer/draft201909/meta.rb +320 -0
  9. data/lib/json_schemer/draft201909/vocab/applicator.rb +104 -0
  10. data/lib/json_schemer/draft201909/vocab/core.rb +45 -0
  11. data/lib/json_schemer/draft201909/vocab.rb +31 -0
  12. data/lib/json_schemer/draft202012/meta.rb +364 -0
  13. data/lib/json_schemer/draft202012/vocab/applicator.rb +382 -0
  14. data/lib/json_schemer/draft202012/vocab/content.rb +52 -0
  15. data/lib/json_schemer/draft202012/vocab/core.rb +160 -0
  16. data/lib/json_schemer/draft202012/vocab/format_annotation.rb +23 -0
  17. data/lib/json_schemer/draft202012/vocab/format_assertion.rb +23 -0
  18. data/lib/json_schemer/draft202012/vocab/meta_data.rb +30 -0
  19. data/lib/json_schemer/draft202012/vocab/unevaluated.rb +94 -0
  20. data/lib/json_schemer/draft202012/vocab/validation.rb +286 -0
  21. data/lib/json_schemer/draft202012/vocab.rb +105 -0
  22. data/lib/json_schemer/draft4/meta.rb +161 -0
  23. data/lib/json_schemer/draft4/vocab/validation.rb +39 -0
  24. data/lib/json_schemer/draft4/vocab.rb +18 -0
  25. data/lib/json_schemer/draft6/meta.rb +172 -0
  26. data/lib/json_schemer/draft6/vocab.rb +16 -0
  27. data/lib/json_schemer/draft7/meta.rb +183 -0
  28. data/lib/json_schemer/draft7/vocab/validation.rb +69 -0
  29. data/lib/json_schemer/draft7/vocab.rb +30 -0
  30. data/lib/json_schemer/errors.rb +1 -0
  31. data/lib/json_schemer/format/duration.rb +23 -0
  32. data/lib/json_schemer/format/json_pointer.rb +18 -0
  33. data/lib/json_schemer/format.rb +128 -106
  34. data/lib/json_schemer/keyword.rb +53 -0
  35. data/lib/json_schemer/location.rb +25 -0
  36. data/lib/json_schemer/openapi.rb +40 -0
  37. data/lib/json_schemer/openapi30/document.rb +1672 -0
  38. data/lib/json_schemer/openapi30/meta.rb +32 -0
  39. data/lib/json_schemer/openapi30/vocab/base.rb +18 -0
  40. data/lib/json_schemer/openapi30/vocab.rb +12 -0
  41. data/lib/json_schemer/openapi31/document.rb +1557 -0
  42. data/lib/json_schemer/openapi31/meta.rb +136 -0
  43. data/lib/json_schemer/openapi31/vocab/base.rb +127 -0
  44. data/lib/json_schemer/openapi31/vocab.rb +18 -0
  45. data/lib/json_schemer/output.rb +56 -0
  46. data/lib/json_schemer/result.rb +229 -0
  47. data/lib/json_schemer/schema.rb +423 -0
  48. data/lib/json_schemer/version.rb +1 -1
  49. data/lib/json_schemer.rb +198 -24
  50. metadata +71 -10
  51. data/lib/json_schemer/schema/base.rb +0 -677
  52. data/lib/json_schemer/schema/draft4.json +0 -149
  53. data/lib/json_schemer/schema/draft4.rb +0 -44
  54. data/lib/json_schemer/schema/draft6.json +0 -155
  55. data/lib/json_schemer/schema/draft6.rb +0 -25
  56. data/lib/json_schemer/schema/draft7.json +0 -172
  57. data/lib/json_schemer/schema/draft7.rb +0 -32
@@ -0,0 +1,364 @@
1
+ # frozen_string_literal: true
2
+ module JSONSchemer
3
+ module Draft202012
4
+ BASE_URI = URI('https://json-schema.org/draft/2020-12/schema')
5
+ FORMATS = {
6
+ 'date-time' => Format::DATE_TIME,
7
+ 'date' => Format::DATE,
8
+ 'time' => Format::TIME,
9
+ 'duration' => Format::DURATION,
10
+ 'email' => Format::EMAIL,
11
+ 'idn-email' => Format::IDN_EMAIL,
12
+ 'hostname' => Format::HOSTNAME,
13
+ 'idn-hostname' => Format::IDN_HOSTNAME,
14
+ 'ipv4' => Format::IPV4,
15
+ 'ipv6' => Format::IPV6,
16
+ 'uri' => Format::URI,
17
+ 'uri-reference' => Format::URI_REFERENCE,
18
+ 'iri' => Format::IRI,
19
+ 'iri-reference' => Format::IRI_REFERENCE,
20
+ 'uuid' => Format::UUID,
21
+ 'uri-template' => Format::URI_TEMPLATE,
22
+ 'json-pointer' => Format::JSON_POINTER,
23
+ 'relative-json-pointer' => Format::RELATIVE_JSON_POINTER,
24
+ 'regex' => Format::REGEX
25
+ }
26
+ CONTENT_ENCODINGS = {
27
+ 'base64' => ContentEncoding::BASE64
28
+ }
29
+ CONTENT_MEDIA_TYPES = {
30
+ 'application/json' => ContentMediaType::JSON
31
+ }
32
+ SCHEMA = {
33
+ '$schema' => 'https://json-schema.org/draft/2020-12/schema',
34
+ '$id' => 'https://json-schema.org/draft/2020-12/schema',
35
+ '$vocabulary' => {
36
+ 'https://json-schema.org/draft/2020-12/vocab/core' => true,
37
+ 'https://json-schema.org/draft/2020-12/vocab/applicator' => true,
38
+ 'https://json-schema.org/draft/2020-12/vocab/unevaluated' => true,
39
+ 'https://json-schema.org/draft/2020-12/vocab/validation' => true,
40
+ 'https://json-schema.org/draft/2020-12/vocab/meta-data' => true,
41
+ 'https://json-schema.org/draft/2020-12/vocab/format-annotation' => true,
42
+ 'https://json-schema.org/draft/2020-12/vocab/content' => true
43
+ },
44
+ '$dynamicAnchor' => 'meta',
45
+ 'title' => 'Core and Validation specifications meta-schema',
46
+ 'allOf' => [
47
+ {'$ref' => 'meta/core'},
48
+ {'$ref' => 'meta/applicator'},
49
+ {'$ref' => 'meta/unevaluated'},
50
+ {'$ref' => 'meta/validation'},
51
+ {'$ref' => 'meta/meta-data'},
52
+ {'$ref' => 'meta/format-annotation'},
53
+ {'$ref' => 'meta/content'}
54
+ ],
55
+ 'type' => ['object', 'boolean'],
56
+ '$comment' => 'This meta-schema also defines keywords that have appeared in previous drafts in order to prevent incompatible extensions as they remain in common use.',
57
+ 'properties' => {
58
+ 'definitions' => {
59
+ '$comment' => '"definitions" has been replaced by "$defs".',
60
+ 'type' => 'object',
61
+ 'additionalProperties' => { '$dynamicRef' => '#meta' },
62
+ 'deprecated' => true,
63
+ 'default' => {}
64
+ },
65
+ 'dependencies' => {
66
+ '$comment' => '"dependencies" has been split and replaced by "dependentSchemas" and "dependentRequired" in order to serve their differing semantics.',
67
+ 'type' => 'object',
68
+ 'additionalProperties' => {
69
+ 'anyOf' => [
70
+ { '$dynamicRef' => '#meta' },
71
+ { '$ref' => 'meta/validation#/$defs/stringArray' }
72
+ ]
73
+ },
74
+ 'deprecated' => true,
75
+ 'default' => {}
76
+ },
77
+ '$recursiveAnchor' => {
78
+ '$comment' => '"$recursiveAnchor" has been replaced by "$dynamicAnchor".',
79
+ '$ref' => 'meta/core#/$defs/anchorString',
80
+ 'deprecated' => true
81
+ },
82
+ '$recursiveRef' => {
83
+ '$comment' => '"$recursiveRef" has been replaced by "$dynamicRef".',
84
+ '$ref' => 'meta/core#/$defs/uriReferenceString',
85
+ 'deprecated' => true
86
+ }
87
+ }
88
+ }
89
+
90
+ module Meta
91
+ CORE = {
92
+ '$schema' => 'https://json-schema.org/draft/2020-12/schema',
93
+ '$id' => 'https://json-schema.org/draft/2020-12/meta/core',
94
+ '$dynamicAnchor' => 'meta',
95
+ 'title' => 'Core vocabulary meta-schema',
96
+ 'type' => ['object', 'boolean'],
97
+ 'properties' => {
98
+ '$id' => {
99
+ '$ref' => '#/$defs/uriReferenceString',
100
+ '$comment' => 'Non-empty fragments not allowed.',
101
+ 'pattern' => '^[^#]*#?$'
102
+ },
103
+ '$schema' => { '$ref' => '#/$defs/uriString' },
104
+ '$ref' => { '$ref' => '#/$defs/uriReferenceString' },
105
+ '$anchor' => { '$ref' => '#/$defs/anchorString' },
106
+ '$dynamicRef' => { '$ref' => '#/$defs/uriReferenceString' },
107
+ '$dynamicAnchor' => { '$ref' => '#/$defs/anchorString' },
108
+ '$vocabulary' => {
109
+ 'type' => 'object',
110
+ 'propertyNames' => { '$ref' => '#/$defs/uriString' },
111
+ 'additionalProperties' => {
112
+ 'type' => 'boolean'
113
+ }
114
+ },
115
+ '$comment' => {
116
+ 'type' => 'string'
117
+ },
118
+ '$defs' => {
119
+ 'type' => 'object',
120
+ 'additionalProperties' => { '$dynamicRef' => '#meta' }
121
+ }
122
+ },
123
+ '$defs' => {
124
+ 'anchorString' => {
125
+ 'type' => 'string',
126
+ 'pattern' => '^[A-Za-z_][-A-Za-z0-9._]*$'
127
+ },
128
+ 'uriString' => {
129
+ 'type' => 'string',
130
+ 'format' => 'uri'
131
+ },
132
+ 'uriReferenceString' => {
133
+ 'type' => 'string',
134
+ 'format' => 'uri-reference'
135
+ }
136
+ }
137
+ }
138
+ APPLICATOR = {
139
+ '$schema' => 'https://json-schema.org/draft/2020-12/schema',
140
+ '$id' => 'https://json-schema.org/draft/2020-12/meta/applicator',
141
+ '$dynamicAnchor' => 'meta',
142
+ 'title' => 'Applicator vocabulary meta-schema',
143
+ 'type' => ['object', 'boolean'],
144
+ 'properties' => {
145
+ 'prefixItems' => { '$ref' => '#/$defs/schemaArray' },
146
+ 'items' => { '$dynamicRef' => '#meta' },
147
+ 'contains' => { '$dynamicRef' => '#meta' },
148
+ 'additionalProperties' => { '$dynamicRef' => '#meta' },
149
+ 'properties' => {
150
+ 'type' => 'object',
151
+ 'additionalProperties' => { '$dynamicRef' => '#meta' },
152
+ 'default' => {}
153
+ },
154
+ 'patternProperties' => {
155
+ 'type' => 'object',
156
+ 'additionalProperties' => { '$dynamicRef' => '#meta' },
157
+ 'propertyNames' => { 'format' => 'regex' },
158
+ 'default' => {}
159
+ },
160
+ 'dependentSchemas' => {
161
+ 'type' => 'object',
162
+ 'additionalProperties' => { '$dynamicRef' => '#meta' },
163
+ 'default' => {}
164
+ },
165
+ 'propertyNames' => { '$dynamicRef' => '#meta' },
166
+ 'if' => { '$dynamicRef' => '#meta' },
167
+ 'then' => { '$dynamicRef' => '#meta' },
168
+ 'else' => { '$dynamicRef' => '#meta' },
169
+ 'allOf' => { '$ref' => '#/$defs/schemaArray' },
170
+ 'anyOf' => { '$ref' => '#/$defs/schemaArray' },
171
+ 'oneOf' => { '$ref' => '#/$defs/schemaArray' },
172
+ 'not' => { '$dynamicRef' => '#meta' }
173
+ },
174
+ '$defs' => {
175
+ 'schemaArray' => {
176
+ 'type' => 'array',
177
+ 'minItems' => 1,
178
+ 'items' => { '$dynamicRef' => '#meta' }
179
+ }
180
+ }
181
+ }
182
+ UNEVALUATED = {
183
+ '$schema' => 'https://json-schema.org/draft/2020-12/schema',
184
+ '$id' => 'https://json-schema.org/draft/2020-12/meta/unevaluated',
185
+ '$dynamicAnchor' => 'meta',
186
+ 'title' => 'Unevaluated applicator vocabulary meta-schema',
187
+ 'type' => ['object', 'boolean'],
188
+ 'properties' => {
189
+ 'unevaluatedItems' => { '$dynamicRef' => '#meta' },
190
+ 'unevaluatedProperties' => { '$dynamicRef' => '#meta' }
191
+ }
192
+ }
193
+ VALIDATION = {
194
+ '$schema' => 'https://json-schema.org/draft/2020-12/schema',
195
+ '$id' => 'https://json-schema.org/draft/2020-12/meta/validation',
196
+ '$dynamicAnchor' => 'meta',
197
+ 'title' => 'Validation vocabulary meta-schema',
198
+ 'type' => ['object', 'boolean'],
199
+ 'properties' => {
200
+ 'type' => {
201
+ 'anyOf' => [
202
+ { '$ref' => '#/$defs/simpleTypes' },
203
+ {
204
+ 'type' => 'array',
205
+ 'items' => { '$ref' => '#/$defs/simpleTypes' },
206
+ 'minItems' => 1,
207
+ 'uniqueItems' => true
208
+ }
209
+ ]
210
+ },
211
+ 'const' => true,
212
+ 'enum' => {
213
+ 'type' => 'array',
214
+ 'items' => true
215
+ },
216
+ 'multipleOf' => {
217
+ 'type' => 'number',
218
+ 'exclusiveMinimum' => 0
219
+ },
220
+ 'maximum' => {
221
+ 'type' => 'number'
222
+ },
223
+ 'exclusiveMaximum' => {
224
+ 'type' => 'number'
225
+ },
226
+ 'minimum' => {
227
+ 'type' => 'number'
228
+ },
229
+ 'exclusiveMinimum' => {
230
+ 'type' => 'number'
231
+ },
232
+ 'maxLength' => { '$ref' => '#/$defs/nonNegativeInteger' },
233
+ 'minLength' => { '$ref' => '#/$defs/nonNegativeIntegerDefault0' },
234
+ 'pattern' => {
235
+ 'type' => 'string',
236
+ 'format' => 'regex'
237
+ },
238
+ 'maxItems' => { '$ref' => '#/$defs/nonNegativeInteger' },
239
+ 'minItems' => { '$ref' => '#/$defs/nonNegativeIntegerDefault0' },
240
+ 'uniqueItems' => {
241
+ 'type' => 'boolean',
242
+ 'default' => false
243
+ },
244
+ 'maxContains' => { '$ref' => '#/$defs/nonNegativeInteger' },
245
+ 'minContains' => {
246
+ '$ref' => '#/$defs/nonNegativeInteger',
247
+ 'default' => 1
248
+ },
249
+ 'maxProperties' => { '$ref' => '#/$defs/nonNegativeInteger' },
250
+ 'minProperties' => { '$ref' => '#/$defs/nonNegativeIntegerDefault0' },
251
+ 'required' => { '$ref' => '#/$defs/stringArray' },
252
+ 'dependentRequired' => {
253
+ 'type' => 'object',
254
+ 'additionalProperties' => {
255
+ '$ref' => '#/$defs/stringArray'
256
+ }
257
+ }
258
+ },
259
+ '$defs' => {
260
+ 'nonNegativeInteger' => {
261
+ 'type' => 'integer',
262
+ 'minimum' => 0
263
+ },
264
+ 'nonNegativeIntegerDefault0' => {
265
+ '$ref' => '#/$defs/nonNegativeInteger',
266
+ 'default' => 0
267
+ },
268
+ 'simpleTypes' => {
269
+ 'enum' => [
270
+ 'array',
271
+ 'boolean',
272
+ 'integer',
273
+ 'null',
274
+ 'number',
275
+ 'object',
276
+ 'string'
277
+ ]
278
+ },
279
+ 'stringArray' => {
280
+ 'type' => 'array',
281
+ 'items' => { 'type' => 'string' },
282
+ 'uniqueItems' => true,
283
+ 'default' => []
284
+ }
285
+ }
286
+ }
287
+ META_DATA = {
288
+ '$schema' => 'https://json-schema.org/draft/2020-12/schema',
289
+ '$id' => 'https://json-schema.org/draft/2020-12/meta/meta-data',
290
+ '$dynamicAnchor' => 'meta',
291
+ 'title' => 'Meta-data vocabulary meta-schema',
292
+ 'type' => ['object', 'boolean'],
293
+ 'properties' => {
294
+ 'title' => {
295
+ 'type' => 'string'
296
+ },
297
+ 'description' => {
298
+ 'type' => 'string'
299
+ },
300
+ 'default' => true,
301
+ 'deprecated' => {
302
+ 'type' => 'boolean',
303
+ 'default' => false
304
+ },
305
+ 'readOnly' => {
306
+ 'type' => 'boolean',
307
+ 'default' => false
308
+ },
309
+ 'writeOnly' => {
310
+ 'type' => 'boolean',
311
+ 'default' => false
312
+ },
313
+ 'examples' => {
314
+ 'type' => 'array',
315
+ 'items' => true
316
+ }
317
+ }
318
+ }
319
+ FORMAT_ANNOTATION = {
320
+ '$schema' => 'https://json-schema.org/draft/2020-12/schema',
321
+ '$id' => 'https://json-schema.org/draft/2020-12/meta/format-annotation',
322
+ '$dynamicAnchor' => 'meta',
323
+ 'title' => 'Format vocabulary meta-schema for annotation results',
324
+ 'type' => ['object', 'boolean'],
325
+ 'properties' => {
326
+ 'format' => { 'type' => 'string' }
327
+ }
328
+ }
329
+ FORMAT_ASSERTION = {
330
+ '$schema' => 'https://json-schema.org/draft/2020-12/schema',
331
+ '$id' => 'https://json-schema.org/draft/2020-12/meta/format-assertion',
332
+ '$dynamicAnchor' => 'meta',
333
+ 'title' => 'Format vocabulary meta-schema for assertion results',
334
+ 'type' => ['object', 'boolean'],
335
+ 'properties' => {
336
+ 'format' => { 'type' => 'string' }
337
+ }
338
+ }
339
+ CONTENT = {
340
+ '$schema' => 'https://json-schema.org/draft/2020-12/schema',
341
+ '$id' => 'https://json-schema.org/draft/2020-12/meta/content',
342
+ '$dynamicAnchor' => 'meta',
343
+ 'title' => 'Content vocabulary meta-schema',
344
+ 'type' => ['object', 'boolean'],
345
+ 'properties' => {
346
+ 'contentEncoding' => { 'type' => 'string' },
347
+ 'contentMediaType' => { 'type' => 'string' },
348
+ 'contentSchema' => { '$dynamicRef' => '#meta' }
349
+ }
350
+ }
351
+
352
+ SCHEMAS = {
353
+ URI('https://json-schema.org/draft/2020-12/meta/core') => CORE,
354
+ URI('https://json-schema.org/draft/2020-12/meta/applicator') => APPLICATOR,
355
+ URI('https://json-schema.org/draft/2020-12/meta/unevaluated') => UNEVALUATED,
356
+ URI('https://json-schema.org/draft/2020-12/meta/validation') => VALIDATION,
357
+ URI('https://json-schema.org/draft/2020-12/meta/meta-data') => META_DATA,
358
+ URI('https://json-schema.org/draft/2020-12/meta/format-annotation') => FORMAT_ANNOTATION,
359
+ URI('https://json-schema.org/draft/2020-12/meta/format-assertion') => FORMAT_ASSERTION,
360
+ URI('https://json-schema.org/draft/2020-12/meta/content') => CONTENT
361
+ }
362
+ end
363
+ end
364
+ end