@swagger-api/apidom-ns-openapi-3-1 1.0.0-beta.8 → 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +191 -0
- package/README.md +371 -1
- package/dist/apidom-ns-openapi-3-1.browser.js +29414 -24750
- package/dist/apidom-ns-openapi-3-1.browser.min.js +1 -1
- package/package.json +10 -9
- package/src/elements/Schema.cjs +2 -427
- package/src/elements/Schema.mjs +2 -427
- package/src/index.cjs +3 -1
- package/src/index.mjs +1 -0
- package/src/refractor/plugins/normalize-discriminator-mapping.cjs +173 -0
- package/src/refractor/plugins/normalize-discriminator-mapping.mjs +167 -0
- package/src/refractor/plugins/replace-empty-element.cjs +2 -1
- package/src/refractor/plugins/replace-empty-element.mjs +3 -2
- package/src/refractor/specification.cjs +55 -157
- package/src/refractor/specification.mjs +13 -115
- package/src/refractor/toolbox.cjs +2 -2
- package/src/refractor/toolbox.mjs +1 -1
- package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.cjs +13 -0
- package/src/refractor/visitors/open-api-3-1/components/SchemasVisitor.mjs +13 -2
- package/src/refractor/visitors/open-api-3-1/schema/$defsVisitor.cjs +2 -10
- package/src/refractor/visitors/open-api-3-1/schema/$defsVisitor.mjs +4 -9
- package/src/refractor/visitors/open-api-3-1/schema/AllOfVisitor.cjs +2 -25
- package/src/refractor/visitors/open-api-3-1/schema/AllOfVisitor.mjs +2 -23
- package/src/refractor/visitors/open-api-3-1/schema/AnyOfVisitor.cjs +2 -25
- package/src/refractor/visitors/open-api-3-1/schema/AnyOfVisitor.mjs +2 -23
- package/src/refractor/visitors/open-api-3-1/schema/DependentSchemasVisitor.cjs +2 -14
- package/src/refractor/visitors/open-api-3-1/schema/DependentSchemasVisitor.mjs +2 -12
- package/src/refractor/visitors/open-api-3-1/schema/OneOfVisitor.cjs +2 -25
- package/src/refractor/visitors/open-api-3-1/schema/OneOfVisitor.mjs +2 -23
- package/src/refractor/visitors/open-api-3-1/schema/PatternPropertiesVisitor.cjs +2 -14
- package/src/refractor/visitors/open-api-3-1/schema/PatternPropertiesVisitor.mjs +2 -12
- package/src/refractor/visitors/open-api-3-1/schema/PrefixItemsVisitor.cjs +2 -25
- package/src/refractor/visitors/open-api-3-1/schema/PrefixItemsVisitor.mjs +2 -23
- package/src/refractor/visitors/open-api-3-1/schema/PropertiesVisitor.cjs +2 -14
- package/src/refractor/visitors/open-api-3-1/schema/PropertiesVisitor.mjs +2 -12
- package/src/refractor/visitors/open-api-3-1/schema/index.cjs +10 -31
- package/src/refractor/visitors/open-api-3-1/schema/index.mjs +12 -33
- package/types/apidom-ns-openapi-3-1.d.ts +183 -408
- package/src/refractor/visitors/open-api-3-1/schema/$refVisitor.cjs +0 -16
- package/src/refractor/visitors/open-api-3-1/schema/$refVisitor.mjs +0 -12
- package/src/refractor/visitors/open-api-3-1/schema/$vocabularyVisitor.cjs +0 -16
- package/src/refractor/visitors/open-api-3-1/schema/$vocabularyVisitor.mjs +0 -12
- package/src/refractor/visitors/open-api-3-1/schema/DependentRequiredVisitor.cjs +0 -16
- package/src/refractor/visitors/open-api-3-1/schema/DependentRequiredVisitor.mjs +0 -12
- package/src/refractor/visitors/open-api-3-1/schema/EnumVisitor.cjs +0 -16
- package/src/refractor/visitors/open-api-3-1/schema/EnumVisitor.mjs +0 -12
- package/src/refractor/visitors/open-api-3-1/schema/ExamplesVisitor.cjs +0 -16
- package/src/refractor/visitors/open-api-3-1/schema/ExamplesVisitor.mjs +0 -12
- package/src/refractor/visitors/open-api-3-1/schema/ParentSchemaAwareVisitor.cjs +0 -17
- package/src/refractor/visitors/open-api-3-1/schema/ParentSchemaAwareVisitor.mjs +0 -13
- package/src/refractor/visitors/open-api-3-1/schema/RequiredVisitor.cjs +0 -16
- package/src/refractor/visitors/open-api-3-1/schema/RequiredVisitor.mjs +0 -12
- package/src/refractor/visitors/open-api-3-1/schema/TypeVisitor.cjs +0 -21
- package/src/refractor/visitors/open-api-3-1/schema/TypeVisitor.mjs +0 -17
package/src/elements/Schema.mjs
CHANGED
|
@@ -1,438 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JSONSchemaElement } from '@swagger-api/apidom-ns-json-schema-2020-12';
|
|
2
2
|
/**
|
|
3
3
|
* @public
|
|
4
4
|
*/
|
|
5
|
-
class Schema extends
|
|
5
|
+
class Schema extends JSONSchemaElement {
|
|
6
6
|
constructor(content, meta, attributes) {
|
|
7
7
|
super(content, meta, attributes);
|
|
8
8
|
this.element = 'schema';
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Core vocabulary
|
|
13
|
-
*
|
|
14
|
-
* URI: https://json-schema.org/draft/2020-12/vocab/core
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
get $schema() {
|
|
18
|
-
return this.get('$schema');
|
|
19
|
-
}
|
|
20
|
-
set $schema($schema) {
|
|
21
|
-
this.set('$schema', $schema);
|
|
22
|
-
}
|
|
23
|
-
get $vocabulary() {
|
|
24
|
-
return this.get('$vocabulary');
|
|
25
|
-
}
|
|
26
|
-
set $vocabulary($vocabulary) {
|
|
27
|
-
this.set('$vocabulary', $vocabulary);
|
|
28
|
-
}
|
|
29
|
-
get $id() {
|
|
30
|
-
return this.get('$id');
|
|
31
|
-
}
|
|
32
|
-
set $id($id) {
|
|
33
|
-
this.set('$id', $id);
|
|
34
|
-
}
|
|
35
|
-
get $anchor() {
|
|
36
|
-
return this.get('$anchor');
|
|
37
|
-
}
|
|
38
|
-
set $anchor($anchor) {
|
|
39
|
-
this.set('$anchor', $anchor);
|
|
40
|
-
}
|
|
41
|
-
get $dynamicAnchor() {
|
|
42
|
-
return this.get('$dynamicAnchor');
|
|
43
|
-
}
|
|
44
|
-
set $dynamicAnchor($dynamicAnchor) {
|
|
45
|
-
this.set('$dynamicAnchor', $dynamicAnchor);
|
|
46
|
-
}
|
|
47
|
-
get $dynamicRef() {
|
|
48
|
-
return this.get('$dynamicRef');
|
|
49
|
-
}
|
|
50
|
-
set $dynamicRef($dynamicRef) {
|
|
51
|
-
this.set('$dynamicRef', $dynamicRef);
|
|
52
|
-
}
|
|
53
|
-
get $ref() {
|
|
54
|
-
return this.get('$ref');
|
|
55
|
-
}
|
|
56
|
-
set $ref($ref) {
|
|
57
|
-
this.set('$ref', $ref);
|
|
58
|
-
}
|
|
59
|
-
get $defs() {
|
|
60
|
-
return this.get('$defs');
|
|
61
|
-
}
|
|
62
|
-
set $defs($defs) {
|
|
63
|
-
this.set('$defs', $defs);
|
|
64
|
-
}
|
|
65
|
-
get $comment() {
|
|
66
|
-
return this.get('$comment');
|
|
67
|
-
}
|
|
68
|
-
set $comment($comment) {
|
|
69
|
-
this.set('$comment', $comment);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Applicator vocabulary
|
|
74
|
-
*
|
|
75
|
-
* URI: https://json-schema.org/draft/2020-12/vocab/applicator
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
get allOf() {
|
|
79
|
-
return this.get('allOf');
|
|
80
|
-
}
|
|
81
|
-
set allOf(allOf) {
|
|
82
|
-
this.set('allOf', allOf);
|
|
83
|
-
}
|
|
84
|
-
get anyOf() {
|
|
85
|
-
return this.get('anyOf');
|
|
86
|
-
}
|
|
87
|
-
set anyOf(anyOf) {
|
|
88
|
-
this.set('anyOf', anyOf);
|
|
89
|
-
}
|
|
90
|
-
get oneOf() {
|
|
91
|
-
return this.get('oneOf');
|
|
92
|
-
}
|
|
93
|
-
set oneOf(oneOf) {
|
|
94
|
-
this.set('oneOf', oneOf);
|
|
95
|
-
}
|
|
96
|
-
get not() {
|
|
97
|
-
return this.get('not');
|
|
98
|
-
}
|
|
99
|
-
set not(not) {
|
|
100
|
-
this.set('not', not);
|
|
101
|
-
}
|
|
102
|
-
get if() {
|
|
103
|
-
return this.get('if');
|
|
104
|
-
}
|
|
105
|
-
set if(ifSchema) {
|
|
106
|
-
this.set('if', ifSchema);
|
|
107
|
-
}
|
|
108
|
-
get then() {
|
|
109
|
-
return this.get('then');
|
|
110
|
-
}
|
|
111
|
-
set then(thenSchema) {
|
|
112
|
-
this.set('then', thenSchema);
|
|
113
|
-
}
|
|
114
|
-
get else() {
|
|
115
|
-
return this.get('else');
|
|
116
|
-
}
|
|
117
|
-
set else(elseSchema) {
|
|
118
|
-
this.set('else', elseSchema);
|
|
119
|
-
}
|
|
120
|
-
get dependentSchemas() {
|
|
121
|
-
return this.get('dependentSchemas');
|
|
122
|
-
}
|
|
123
|
-
set dependentSchemas(dependentSchemas) {
|
|
124
|
-
this.set('dependentSchemas', dependentSchemas);
|
|
125
|
-
}
|
|
126
|
-
get prefixItems() {
|
|
127
|
-
return this.get('prefixItems');
|
|
128
|
-
}
|
|
129
|
-
set prefixItems(prefixItems) {
|
|
130
|
-
this.set('prefixItems', prefixItems);
|
|
131
|
-
}
|
|
132
|
-
get items() {
|
|
133
|
-
return this.get('items');
|
|
134
|
-
}
|
|
135
|
-
set items(items) {
|
|
136
|
-
this.set('items', items);
|
|
137
|
-
}
|
|
138
|
-
get containsProp() {
|
|
139
|
-
return this.get('contains');
|
|
140
|
-
}
|
|
141
|
-
set containsProp(containsProp) {
|
|
142
|
-
this.set('contains', containsProp);
|
|
143
|
-
}
|
|
144
|
-
get properties() {
|
|
145
|
-
return this.get('properties');
|
|
146
|
-
}
|
|
147
|
-
set properties(properties) {
|
|
148
|
-
this.set('properties', properties);
|
|
149
|
-
}
|
|
150
|
-
get patternProperties() {
|
|
151
|
-
return this.get('patternProperties');
|
|
152
|
-
}
|
|
153
|
-
set patternProperties(patternProperties) {
|
|
154
|
-
this.set('patternProperties', patternProperties);
|
|
155
|
-
}
|
|
156
|
-
get additionalProperties() {
|
|
157
|
-
return this.get('additionalProperties');
|
|
158
|
-
}
|
|
159
|
-
set additionalProperties(additionalProperties) {
|
|
160
|
-
this.set('additionalProperties', additionalProperties);
|
|
161
|
-
}
|
|
162
|
-
get propertyNames() {
|
|
163
|
-
return this.get('propertyNames');
|
|
164
|
-
}
|
|
165
|
-
set propertyNames(propertyNames) {
|
|
166
|
-
this.set('propertyNames', propertyNames);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Unevaluated Locations vocabulary
|
|
171
|
-
*
|
|
172
|
-
* URI: https://json-schema.org/draft/2020-12/vocab/unevaluated
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
get unevaluatedItems() {
|
|
176
|
-
return this.get('unevaluatedItems');
|
|
177
|
-
}
|
|
178
|
-
set unevaluatedItems(unevaluatedItems) {
|
|
179
|
-
this.set('unevaluatedItems', unevaluatedItems);
|
|
180
|
-
}
|
|
181
|
-
get unevaluatedProperties() {
|
|
182
|
-
return this.get('unevaluatedProperties');
|
|
183
|
-
}
|
|
184
|
-
set unevaluatedProperties(unevaluatedProperties) {
|
|
185
|
-
this.set('unevaluatedProperties', unevaluatedProperties);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Validation vocabulary
|
|
190
|
-
*
|
|
191
|
-
* URI: https://json-schema.org/draft/2020-12/vocab/validation
|
|
192
|
-
*/
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Validation Keywords for Any Instance Type
|
|
196
|
-
*
|
|
197
|
-
* URI: https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.1
|
|
198
|
-
*/
|
|
199
|
-
|
|
200
|
-
get type() {
|
|
201
|
-
return this.get('type');
|
|
202
|
-
}
|
|
203
|
-
set type(type) {
|
|
204
|
-
this.set('type', type);
|
|
205
|
-
}
|
|
206
|
-
get enum() {
|
|
207
|
-
return this.get('enum');
|
|
208
|
-
}
|
|
209
|
-
set enum(enumVal) {
|
|
210
|
-
this.set('enum', enumVal);
|
|
211
|
-
}
|
|
212
|
-
get const() {
|
|
213
|
-
return this.get('const');
|
|
214
|
-
}
|
|
215
|
-
set const(constVal) {
|
|
216
|
-
this.set('const', constVal);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Validation Keywords for Numeric Instances (number and integer)
|
|
221
|
-
*
|
|
222
|
-
* URI: https://json-schema.org/draft/2020-12/json-schema-validation.html#numeric
|
|
223
|
-
*/
|
|
224
|
-
|
|
225
|
-
get multipleOf() {
|
|
226
|
-
return this.get('multipleOf');
|
|
227
|
-
}
|
|
228
|
-
set multipleOf(multipleOf) {
|
|
229
|
-
this.set('multipleOf', multipleOf);
|
|
230
|
-
}
|
|
231
|
-
get maximum() {
|
|
232
|
-
return this.get('maximum');
|
|
233
|
-
}
|
|
234
|
-
set maximum(maximum) {
|
|
235
|
-
this.set('maximum', maximum);
|
|
236
|
-
}
|
|
237
|
-
get exclusiveMaximum() {
|
|
238
|
-
return this.get('exclusiveMaximum');
|
|
239
|
-
}
|
|
240
|
-
set exclusiveMaximum(exclusiveMaximum) {
|
|
241
|
-
this.set('exclusiveMaximum', exclusiveMaximum);
|
|
242
|
-
}
|
|
243
|
-
get minimum() {
|
|
244
|
-
return this.get('minimum');
|
|
245
|
-
}
|
|
246
|
-
set minimum(minimum) {
|
|
247
|
-
this.set('minimum', minimum);
|
|
248
|
-
}
|
|
249
|
-
get exclusiveMinimum() {
|
|
250
|
-
return this.get('exclusiveMinimum');
|
|
251
|
-
}
|
|
252
|
-
set exclusiveMinimum(exclusiveMinimum) {
|
|
253
|
-
this.set('exclusiveMinimum', exclusiveMinimum);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Validation Keywords for Strings
|
|
258
|
-
*
|
|
259
|
-
* URI: https://json-schema.org/draft/2020-12/json-schema-validation.html#string
|
|
260
|
-
*/
|
|
261
|
-
|
|
262
|
-
get maxLength() {
|
|
263
|
-
return this.get('maxLength');
|
|
264
|
-
}
|
|
265
|
-
set maxLength(maxLength) {
|
|
266
|
-
this.set('maxLength', maxLength);
|
|
267
|
-
}
|
|
268
|
-
get minLength() {
|
|
269
|
-
return this.get('minLength');
|
|
270
|
-
}
|
|
271
|
-
set minLength(minLength) {
|
|
272
|
-
this.set('minLength', minLength);
|
|
273
|
-
}
|
|
274
|
-
get pattern() {
|
|
275
|
-
return this.get('pattern');
|
|
276
|
-
}
|
|
277
|
-
set pattern(pattern) {
|
|
278
|
-
this.set('pattern', pattern);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Validation Keywords for Arrays
|
|
283
|
-
*
|
|
284
|
-
* URI: https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.4
|
|
285
|
-
*/
|
|
286
|
-
|
|
287
|
-
get maxItems() {
|
|
288
|
-
return this.get('maxItems');
|
|
289
|
-
}
|
|
290
|
-
set maxItems(maxItems) {
|
|
291
|
-
this.set('maxItems', maxItems);
|
|
292
|
-
}
|
|
293
|
-
get minItems() {
|
|
294
|
-
return this.get('minItems');
|
|
295
|
-
}
|
|
296
|
-
set minItems(minItems) {
|
|
297
|
-
this.set('minItems', minItems);
|
|
298
|
-
}
|
|
299
|
-
get uniqueItems() {
|
|
300
|
-
return this.get('uniqueItems');
|
|
301
|
-
}
|
|
302
|
-
set uniqueItems(uniqueItems) {
|
|
303
|
-
this.set('uniqueItems', uniqueItems);
|
|
304
|
-
}
|
|
305
|
-
get maxContains() {
|
|
306
|
-
return this.get('maxContains');
|
|
307
|
-
}
|
|
308
|
-
set maxContains(maxContains) {
|
|
309
|
-
this.set('maxContains', maxContains);
|
|
310
|
-
}
|
|
311
|
-
get minContains() {
|
|
312
|
-
return this.get('minContains');
|
|
313
|
-
}
|
|
314
|
-
set minContains(minContains) {
|
|
315
|
-
this.set('minContains', minContains);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Validation Keywords for Objects
|
|
320
|
-
*
|
|
321
|
-
* URI: https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.6.5
|
|
322
|
-
*/
|
|
323
|
-
|
|
324
|
-
get maxProperties() {
|
|
325
|
-
return this.get('maxProperties');
|
|
326
|
-
}
|
|
327
|
-
set maxProperties(maxProperties) {
|
|
328
|
-
this.set('maxProperties', maxProperties);
|
|
329
|
-
}
|
|
330
|
-
get minProperties() {
|
|
331
|
-
return this.get('minProperties');
|
|
332
|
-
}
|
|
333
|
-
set minProperties(minProperties) {
|
|
334
|
-
this.set('minProperties', minProperties);
|
|
335
|
-
}
|
|
336
|
-
get required() {
|
|
337
|
-
return this.get('required');
|
|
338
|
-
}
|
|
339
|
-
set required(required) {
|
|
340
|
-
this.set('required', required);
|
|
341
|
-
}
|
|
342
|
-
get dependentRequired() {
|
|
343
|
-
return this.get('dependentRequired');
|
|
344
|
-
}
|
|
345
|
-
set dependentRequired(dependentRequired) {
|
|
346
|
-
this.set('dependentRequired', dependentRequired);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Vocabulary for Basic Meta-Data Annotations
|
|
351
|
-
*
|
|
352
|
-
* URI: https://json-schema.org/draft/2020-12/vocab/meta-data
|
|
353
|
-
*/
|
|
354
|
-
|
|
355
|
-
get title() {
|
|
356
|
-
return this.get('title');
|
|
357
|
-
}
|
|
358
|
-
set title(title) {
|
|
359
|
-
this.set('title', title);
|
|
360
|
-
}
|
|
361
|
-
get description() {
|
|
362
|
-
return this.get('description');
|
|
363
|
-
}
|
|
364
|
-
set description(description) {
|
|
365
|
-
this.set('description', description);
|
|
366
|
-
}
|
|
367
|
-
get default() {
|
|
368
|
-
return this.get('default');
|
|
369
|
-
}
|
|
370
|
-
set default(defaultVal) {
|
|
371
|
-
this.set('default', defaultVal);
|
|
372
|
-
}
|
|
373
|
-
get deprecated() {
|
|
374
|
-
return this.get('deprecated');
|
|
375
|
-
}
|
|
376
|
-
set deprecated(deprecated) {
|
|
377
|
-
this.set('deprecated', deprecated);
|
|
378
|
-
}
|
|
379
|
-
get readOnly() {
|
|
380
|
-
return this.get('readOnly');
|
|
381
|
-
}
|
|
382
|
-
set readOnly(readOnly) {
|
|
383
|
-
this.set('readOnly', readOnly);
|
|
384
|
-
}
|
|
385
|
-
get writeOnly() {
|
|
386
|
-
return this.get('writeOnly');
|
|
387
|
-
}
|
|
388
|
-
set writeOnly(writeOnly) {
|
|
389
|
-
this.set('writeOnly', writeOnly);
|
|
390
|
-
}
|
|
391
|
-
get examples() {
|
|
392
|
-
return this.get('examples');
|
|
393
|
-
}
|
|
394
|
-
set examples(examples) {
|
|
395
|
-
this.set('examples', examples);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Vocabularies for Semantic Content With "format"
|
|
400
|
-
*
|
|
401
|
-
* URI: https://json-schema.org/draft/2020-12/vocab/format-annotation
|
|
402
|
-
*/
|
|
403
|
-
|
|
404
|
-
get format() {
|
|
405
|
-
return this.get('format');
|
|
406
|
-
}
|
|
407
|
-
set format(format) {
|
|
408
|
-
this.set('format', format);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Vocabulary for the Contents of String-Encoded Data
|
|
413
|
-
*
|
|
414
|
-
* URI: https://json-schema.org/draft/2020-12/vocab/content
|
|
415
|
-
*/
|
|
416
|
-
|
|
417
|
-
get contentEncoding() {
|
|
418
|
-
return this.get('contentEncoding');
|
|
419
|
-
}
|
|
420
|
-
set contentEncoding(contentEncoding) {
|
|
421
|
-
this.set('contentEncoding', contentEncoding);
|
|
422
|
-
}
|
|
423
|
-
get contentMediaType() {
|
|
424
|
-
return this.get('contentMediaType');
|
|
425
|
-
}
|
|
426
|
-
set contentMediaType(contentMediaType) {
|
|
427
|
-
this.set('contentMediaType', contentMediaType);
|
|
428
|
-
}
|
|
429
|
-
get contentSchema() {
|
|
430
|
-
return this.get('contentSchema');
|
|
431
|
-
}
|
|
432
|
-
set contentSchema(contentSchema) {
|
|
433
|
-
this.set('contentSchema', contentSchema);
|
|
434
|
-
}
|
|
435
|
-
|
|
436
11
|
/**
|
|
437
12
|
* OAS base vocabulary
|
|
438
13
|
*
|
package/src/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
|
4
4
|
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
5
|
exports.__esModule = true;
|
|
6
6
|
exports.isObjectElement = exports.isNumberElement = exports.isNullElement = exports.isMemberElement = exports.isMediaTypeElement = exports.isLinkPrimitiveElement = exports.isLinkElement = exports.isLicenseElement = exports.isJsonSchemaDialectElement = exports.isInfoElement = exports.isExternalDocumentationElement = exports.isExampleElement = exports.isElement = exports.isContactElement = exports.isComponentsElement = exports.isCallbackElement = exports.isBooleanJsonSchemaElement = exports.isBooleanElement = exports.isArrayElement = exports.getNodeType = exports.default = exports.createToolbox = exports.XmlElement = exports.WebhooksElement = exports.Visitor = exports.TagsElement = exports.TagElement = exports.SpecificationVisitor = exports.SpecificationExtensionVisitor = exports.ServersElement = exports.ServerVariablesElement = exports.ServerVariableElement = exports.ServerElement = exports.SecuritySchemeElement = exports.SecurityRequirementElement = exports.SecurityElement = exports.SchemaElement = exports.ResponsesElement = exports.ResponseLinksElement = exports.ResponseHeadersElement = exports.ResponseElement = exports.ResponseContentElement = exports.RequestBodyElement = exports.RequestBodyContentElement = exports.ReferenceElement = exports.PatternedFieldsVisitor = exports.PathsElement = exports.PathItemServersElement = exports.PathItemParametersElement = exports.PathItemElement = exports.ParameterExamplesElement = exports.ParameterElement = exports.ParameterContentElement = exports.OperationTagsElement = exports.OperationServersElement = exports.OperationSecurityElement = exports.OperationParametersElement = exports.OperationElement = exports.OperationCallbacksElement = exports.OpenapiElement = exports.OpenApi3_1Element = exports.OpenAPIMediaTypes = exports.OAuthFlowsElement = exports.OAuthFlowScopesElement = exports.OAuthFlowElement = exports.MixedFieldsVisitor = exports.MediaTypeExamplesElement = exports.MediaTypeEncodingElement = exports.MediaTypeElement = exports.MapVisitor = exports.LinkParametersElement = exports.LinkElement = exports.LicenseElement = exports.JsonSchemaDialectElement = exports.InfoElement = exports.HeaderExamplesElement = exports.HeaderElement = exports.HeaderContentElement = exports.FixedFieldsVisitor = exports.FallbackVisitor = exports.ExternalDocumentationElement = exports.ExampleElement = exports.EncodingHeadersElement = exports.EncodingElement = exports.DiscriminatorMappingElement = exports.DiscriminatorElement = exports.ContactElement = exports.ComponentsSecuritySchemesElement = exports.ComponentsSchemasElement = exports.ComponentsResponsesElement = exports.ComponentsRequestBodiesElement = exports.ComponentsPathItemsElement = exports.ComponentsParametersElement = exports.ComponentsLinksElement = exports.ComponentsHeadersElement = exports.ComponentsExamplesElement = exports.ComponentsElement = exports.ComponentsCallbacksElement = exports.CallbackElement = exports.AlternatingVisitor = void 0;
|
|
7
|
-
exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.refractorPluginNormalizeServers = exports.refractorPluginNormalizeSecurityRequirements = exports.refractorPluginNormalizeParameters = exports.refractorPluginNormalizeParameterExamples = exports.refractorPluginNormalizeOperationIds = exports.refractorPluginNormalizeHeaderExamples = exports.mediaTypes = exports.keyMap = exports.isStringElement = exports.isServersElement = exports.isServerVariableElement = exports.isServerLikeElement = exports.isServerElement = exports.isSecuritySchemeElement = exports.isSecurityRequirementElement = exports.isSchemaElement = exports.isResponsesElement = exports.isResponseElement = exports.isRequestBodyElement = exports.isReferenceLikeElement = exports.isReferenceElementExternal = exports.isReferenceElement = exports.isRefElement = exports.isPathsElement = exports.isPathItemElementExternal = exports.isPathItemElement = exports.isParameterElement = exports.isOperationElement = exports.isOpenapiElement = exports.isOpenApiExtension = exports.isOpenApi3_1Element = void 0;
|
|
7
|
+
exports.specificationObj = exports.refractorPluginReplaceEmptyElement = exports.refractorPluginNormalizeServers = exports.refractorPluginNormalizeSecurityRequirements = exports.refractorPluginNormalizeParameters = exports.refractorPluginNormalizeParameterExamples = exports.refractorPluginNormalizeOperationIds = exports.refractorPluginNormalizeHeaderExamples = exports.refractorPluginNormalizeDiscriminatorMapping = exports.mediaTypes = exports.keyMap = exports.isStringElement = exports.isServersElement = exports.isServerVariableElement = exports.isServerLikeElement = exports.isServerElement = exports.isSecuritySchemeElement = exports.isSecurityRequirementElement = exports.isSchemaElement = exports.isResponsesElement = exports.isResponseElement = exports.isRequestBodyElement = exports.isReferenceLikeElement = exports.isReferenceElementExternal = exports.isReferenceElement = exports.isRefElement = exports.isPathsElement = exports.isPathItemElementExternal = exports.isPathItemElement = exports.isParameterElement = exports.isOperationElement = exports.isOpenapiElement = exports.isOpenApiExtension = exports.isOpenApi3_1Element = void 0;
|
|
8
8
|
var _apidomCore = require("@swagger-api/apidom-core");
|
|
9
9
|
exports.isRefElement = _apidomCore.isRefElement;
|
|
10
10
|
exports.isLinkPrimitiveElement = _apidomCore.isLinkElement;
|
|
@@ -35,6 +35,8 @@ var _normalizeParameterExamples = _interopRequireDefault(require("./refractor/pl
|
|
|
35
35
|
exports.refractorPluginNormalizeParameterExamples = _normalizeParameterExamples.default;
|
|
36
36
|
var _index = _interopRequireDefault(require("./refractor/plugins/normalize-header-examples/index.cjs"));
|
|
37
37
|
exports.refractorPluginNormalizeHeaderExamples = _index.default;
|
|
38
|
+
var _normalizeDiscriminatorMapping = _interopRequireDefault(require("./refractor/plugins/normalize-discriminator-mapping.cjs"));
|
|
39
|
+
exports.refractorPluginNormalizeDiscriminatorMapping = _normalizeDiscriminatorMapping.default;
|
|
38
40
|
var _toolbox = _interopRequireDefault(require("./refractor/toolbox.cjs"));
|
|
39
41
|
exports.createToolbox = _toolbox.default;
|
|
40
42
|
var _specification = _interopRequireDefault(require("./refractor/specification.cjs"));
|
package/src/index.mjs
CHANGED
|
@@ -9,6 +9,7 @@ export { default as refractorPluginNormalizeServers } from "./refractor/plugins/
|
|
|
9
9
|
export { default as refractorPluginNormalizeOperationIds } from "./refractor/plugins/normalize-operation-ids.mjs";
|
|
10
10
|
export { default as refractorPluginNormalizeParameterExamples } from "./refractor/plugins/normalize-parameter-examples.mjs";
|
|
11
11
|
export { default as refractorPluginNormalizeHeaderExamples } from "./refractor/plugins/normalize-header-examples/index.mjs";
|
|
12
|
+
export { default as refractorPluginNormalizeDiscriminatorMapping } from "./refractor/plugins/normalize-discriminator-mapping.mjs";
|
|
12
13
|
export { default as createToolbox } from "./refractor/toolbox.mjs";
|
|
13
14
|
export { default as specificationObj } from "./refractor/specification.mjs";
|
|
14
15
|
export { AlternatingVisitor } from '@swagger-api/apidom-ns-openapi-3-0';
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _apidomCore = require("@swagger-api/apidom-core");
|
|
7
|
+
var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-0");
|
|
8
|
+
var _NormalizeStorage = _interopRequireDefault(require("./normalize-header-examples/NormalizeStorage.cjs"));
|
|
9
|
+
var _predicates = require("../../predicates.cjs");
|
|
10
|
+
var _Discriminator = _interopRequireDefault(require("../../elements/Discriminator.cjs"));
|
|
11
|
+
/**
|
|
12
|
+
* Normalization of Discriminator.mapping field.
|
|
13
|
+
*
|
|
14
|
+
* Discriminator.mapping fields are normalized by adding missing mappings from oneOf/anyOf items
|
|
15
|
+
* of the parent Schema Object and transforming existing mappings to Schema Objects.
|
|
16
|
+
*
|
|
17
|
+
* In case of allOf discriminator, the plugin will add missing mappings based on
|
|
18
|
+
* allOf items of other Schema Objects.
|
|
19
|
+
*
|
|
20
|
+
* The normalized mapping is stored in the Schema.discriminator field as `x-normalized-mapping`.
|
|
21
|
+
*
|
|
22
|
+
* This plugin is designed to be used on dereferenced OpenAPI 3.1 documents.
|
|
23
|
+
*
|
|
24
|
+
* NOTE: this plugin is idempotent
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
const plugin = ({
|
|
32
|
+
storageField = 'x-normalized',
|
|
33
|
+
baseURI = ''
|
|
34
|
+
} = {}) => toolbox => {
|
|
35
|
+
const {
|
|
36
|
+
ancestorLineageToJSONPointer
|
|
37
|
+
} = toolbox;
|
|
38
|
+
let storage;
|
|
39
|
+
let allOfDiscriminatorMapping;
|
|
40
|
+
return {
|
|
41
|
+
visitor: {
|
|
42
|
+
OpenApi3_1Element: {
|
|
43
|
+
enter(element) {
|
|
44
|
+
var _element$getMetaPrope;
|
|
45
|
+
storage = new _NormalizeStorage.default(element, storageField, 'discriminator-mapping');
|
|
46
|
+
allOfDiscriminatorMapping = (_element$getMetaPrope = element.getMetaProperty('allOfDiscriminatorMapping')) != null ? _element$getMetaPrope : new _apidomCore.ObjectElement();
|
|
47
|
+
},
|
|
48
|
+
leave() {
|
|
49
|
+
storage = undefined;
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
SchemaElement: {
|
|
53
|
+
leave(schemaElement, key, parent, path, ancestors) {
|
|
54
|
+
var _parentElement$classe, _schemaElement$discri;
|
|
55
|
+
// no Schema.discriminator field present
|
|
56
|
+
if (!(0, _apidomNsOpenapi.isDiscriminatorElement)(schemaElement.discriminator)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const schemaJSONPointer = ancestorLineageToJSONPointer([...ancestors, parent, schemaElement]);
|
|
60
|
+
|
|
61
|
+
// skip visiting this Schema Object if it's already normalized
|
|
62
|
+
if (storage.includes(schemaJSONPointer)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// skip if both oneOf and anyOf are present
|
|
67
|
+
if ((0, _apidomCore.isArrayElement)(schemaElement.oneOf) && (0, _apidomCore.isArrayElement)(schemaElement.anyOf)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const parentElement = ancestors[ancestors.length - 1];
|
|
71
|
+
const schemaName = schemaElement.getMetaProperty('schemaName');
|
|
72
|
+
const allOfMapping = allOfDiscriminatorMapping.getMember((0, _apidomCore.toValue)(schemaName));
|
|
73
|
+
const hasAllOfMapping =
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
allOfMapping && !(parentElement != null && (_parentElement$classe = parentElement.classes) != null && _parentElement$classe.contains('json-schema-allOf'));
|
|
76
|
+
|
|
77
|
+
// skip if neither oneOf, anyOf nor allOf is present
|
|
78
|
+
if (!(0, _apidomCore.isArrayElement)(schemaElement.oneOf) && !(0, _apidomCore.isArrayElement)(schemaElement.anyOf) && !hasAllOfMapping) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const mapping = (_schemaElement$discri = schemaElement.discriminator.get('mapping')) != null ? _schemaElement$discri : new _apidomCore.ObjectElement();
|
|
82
|
+
const normalizedMapping = new _apidomCore.ObjectElement();
|
|
83
|
+
let isNormalized = true;
|
|
84
|
+
const items = (0, _apidomCore.isArrayElement)(schemaElement.oneOf) ? schemaElement.oneOf : (0, _apidomCore.isArrayElement)(schemaElement.anyOf) ? schemaElement.anyOf : allOfMapping.value;
|
|
85
|
+
items.forEach(item => {
|
|
86
|
+
if (!(0, _predicates.isSchemaElement)(item)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if ((0, _apidomNsOpenapi.isReferenceLikeElement)(item)) {
|
|
90
|
+
isNormalized = false;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const metaRefFields = (0, _apidomCore.toValue)(item.getMetaProperty('ref-fields'));
|
|
94
|
+
const metaRefOrigin = (0, _apidomCore.toValue)(item.getMetaProperty('ref-origin'));
|
|
95
|
+
const metaSchemaName = (0, _apidomCore.toValue)(item.getMetaProperty('schemaName'));
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* handle external references and internal references
|
|
99
|
+
* that don't point to components/schemas/<SchemaName>
|
|
100
|
+
*/
|
|
101
|
+
if (!hasAllOfMapping && (metaRefOrigin !== baseURI || !metaSchemaName && metaRefFields)) {
|
|
102
|
+
let hasMatchingMapping = false;
|
|
103
|
+
mapping.forEach((mappingValue, mappingKey) => {
|
|
104
|
+
var _mappingValueSchema$g;
|
|
105
|
+
const mappingValueSchema = mappingValue.getMetaProperty('ref-schema');
|
|
106
|
+
const mappingValueSchemaRefBaseURI = mappingValueSchema == null || (_mappingValueSchema$g = mappingValueSchema.getMetaProperty('ref-fields')) == null ? void 0 : _mappingValueSchema$g.get('$refBaseURI');
|
|
107
|
+
if (mappingValueSchemaRefBaseURI != null && mappingValueSchemaRefBaseURI.equals(metaRefFields == null ? void 0 : metaRefFields.$refBaseURI)) {
|
|
108
|
+
normalizedMapping.set((0, _apidomCore.toValue)(mappingKey), (0, _apidomCore.cloneShallow)(item));
|
|
109
|
+
hasMatchingMapping = true;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
if (!hasMatchingMapping) {
|
|
113
|
+
isNormalized = false;
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// handle internal references that point to components/schemas/<SchemaName>
|
|
119
|
+
if (metaSchemaName) {
|
|
120
|
+
let hasMatchingMapping = false;
|
|
121
|
+
mapping.forEach((mappingValue, mappingKey) => {
|
|
122
|
+
var _mappingValueSchema$g2;
|
|
123
|
+
const mappingValueSchema = mappingValue.getMetaProperty('ref-schema');
|
|
124
|
+
const mappingValueSchemaName = mappingValueSchema == null ? void 0 : mappingValueSchema.getMetaProperty('schemaName');
|
|
125
|
+
const mappingValueSchemaRefBaseURI = mappingValueSchema == null || (_mappingValueSchema$g2 = mappingValueSchema.getMetaProperty('ref-fields')) == null ? void 0 : _mappingValueSchema$g2.get('$refBaseURI');
|
|
126
|
+
if (mappingValueSchemaName != null && mappingValueSchemaName.equals(metaSchemaName) && (!hasAllOfMapping || mappingValueSchemaRefBaseURI != null && mappingValueSchemaRefBaseURI.equals(metaRefFields == null ? void 0 : metaRefFields.$refBaseURI))) {
|
|
127
|
+
normalizedMapping.set((0, _apidomCore.toValue)(mappingKey), (0, _apidomCore.cloneShallow)(item));
|
|
128
|
+
hasMatchingMapping = true;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// add a new mapping if no matching mapping was found
|
|
133
|
+
if (!hasMatchingMapping) {
|
|
134
|
+
normalizedMapping.set(metaSchemaName, (0, _apidomCore.cloneShallow)(item));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// check if any mapping is not a Schema Object or if any mapping was not normalized
|
|
140
|
+
const mappingKeys = mapping.keys();
|
|
141
|
+
const normalizedMappingKeys = normalizedMapping.keys();
|
|
142
|
+
isNormalized = isNormalized && normalizedMapping.filter(mappingValue => !(0, _predicates.isSchemaElement)(mappingValue)).length === 0 && mappingKeys.every(mappingKey => normalizedMappingKeys.includes(mappingKey));
|
|
143
|
+
if (isNormalized) {
|
|
144
|
+
schemaElement.discriminator.set('x-normalized-mapping', normalizedMapping);
|
|
145
|
+
|
|
146
|
+
// dive in and eliminate cycles that might be created by normalization
|
|
147
|
+
(0, _apidomCore.visit)(schemaElement, {}, {
|
|
148
|
+
// @ts-ignore
|
|
149
|
+
detectCyclesCallback: (node, nodeKey, nodeParent) => {
|
|
150
|
+
if (!nodeParent || !(0, _apidomCore.isMemberElement)(node) || !(0, _apidomCore.isStringElement)(node.key) || !node.key.equals('discriminator') || !(0, _apidomNsOpenapi.isDiscriminatorElement)(node.value)) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const discriminator = (0, _apidomCore.cloneShallow)(node.value);
|
|
154
|
+
const discriminatorCopy = new _Discriminator.default();
|
|
155
|
+
if (discriminator.get('mapping')) {
|
|
156
|
+
discriminatorCopy.mapping = discriminator.get('mapping');
|
|
157
|
+
}
|
|
158
|
+
if (discriminator.get('propertyName')) {
|
|
159
|
+
discriminatorCopy.propertyName = discriminator.get('propertyName');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// eslint-disable-next-line no-param-reassign
|
|
163
|
+
nodeParent[nodeKey] = new _apidomCore.MemberElement(new _apidomCore.StringElement('discriminator'), discriminatorCopy);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
storage.append(schemaJSONPointer);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
var _default = exports.default = plugin;
|