@kubb/plugin-oas 3.10.2 → 3.10.3
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/dist/{OperationGenerator-DiF6WJNP.d.cts → OperationGenerator-BrnQyed_.d.cts} +9 -1
- package/dist/{OperationGenerator-DiF6WJNP.d.ts → OperationGenerator-BrnQyed_.d.ts} +9 -1
- package/dist/Schema-DTc2F3jG.d.cts +32 -0
- package/dist/Schema-Dhz38Get.d.ts +32 -0
- package/dist/{chunk-72MVTXCW.js → chunk-5JWN6NVC.js} +245 -133
- package/dist/chunk-5JWN6NVC.js.map +1 -0
- package/dist/{chunk-DUZZHEQI.cjs → chunk-ES7R7N34.cjs} +6 -6
- package/dist/chunk-ES7R7N34.cjs.map +1 -0
- package/dist/{chunk-BAU7PO7T.js → chunk-JNN4JPWK.js} +4 -4
- package/dist/chunk-JNN4JPWK.js.map +1 -0
- package/dist/{chunk-3Y4QGY6D.js → chunk-PORSNYI5.js} +3 -3
- package/dist/chunk-PORSNYI5.js.map +1 -0
- package/dist/{chunk-Q4HTTWL7.cjs → chunk-PSWNN6SJ.cjs} +245 -133
- package/dist/chunk-PSWNN6SJ.cjs.map +1 -0
- package/dist/{chunk-DN373TFU.js → chunk-RNF2QJEG.js} +4 -4
- package/dist/chunk-RNF2QJEG.js.map +1 -0
- package/dist/{chunk-KXB5DUFD.cjs → chunk-Z2NREI4X.cjs} +4 -4
- package/dist/chunk-Z2NREI4X.cjs.map +1 -0
- package/dist/{chunk-B7KP5ZFA.cjs → chunk-ZVFL3NXX.cjs} +3 -3
- package/dist/chunk-ZVFL3NXX.cjs.map +1 -0
- package/dist/components.cjs +4 -4
- package/dist/components.d.cts +2 -2
- package/dist/components.d.ts +2 -2
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +3 -3
- package/dist/hooks.cjs +9 -9
- package/dist/hooks.d.cts +2 -2
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +3 -3
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/utils.cjs +3 -3
- package/dist/utils.d.cts +10 -3
- package/dist/utils.d.ts +10 -3
- package/dist/utils.js +1 -1
- package/package.json +7 -7
- package/src/SchemaGenerator.ts +271 -132
- package/src/SchemaMapper.ts +1 -0
- package/src/components/Schema.tsx +13 -4
- package/src/generator.tsx +8 -1
- package/src/utils/getSchemaFactory.ts +10 -3
- package/dist/Schema-BbIxCfn7.d.ts +0 -23
- package/dist/Schema-Ds5f4y7m.d.cts +0 -23
- package/dist/chunk-3Y4QGY6D.js.map +0 -1
- package/dist/chunk-72MVTXCW.js.map +0 -1
- package/dist/chunk-B7KP5ZFA.cjs.map +0 -1
- package/dist/chunk-BAU7PO7T.js.map +0 -1
- package/dist/chunk-DN373TFU.js.map +0 -1
- package/dist/chunk-DUZZHEQI.cjs.map +0 -1
- package/dist/chunk-KXB5DUFD.cjs.map +0 -1
- package/dist/chunk-Q4HTTWL7.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkZVFL3NXX_cjs = require('./chunk-ZVFL3NXX.cjs');
|
|
4
4
|
var core = require('@kubb/core');
|
|
5
5
|
var transformers = require('@kubb/core/transformers');
|
|
6
6
|
var utils = require('@kubb/core/utils');
|
|
@@ -209,16 +209,16 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
209
209
|
/**
|
|
210
210
|
* Recursively creates a type literal with the given props.
|
|
211
211
|
*/
|
|
212
|
-
#parseProperties({
|
|
213
|
-
const properties =
|
|
214
|
-
const additionalProperties =
|
|
215
|
-
const required =
|
|
212
|
+
#parseProperties({ schemaObject, name }) {
|
|
213
|
+
const properties = schemaObject?.properties || {};
|
|
214
|
+
const additionalProperties = schemaObject?.additionalProperties;
|
|
215
|
+
const required = schemaObject?.required;
|
|
216
216
|
const propertiesSchemas = Object.keys(properties).map((propertyName) => {
|
|
217
217
|
const validationFunctions = [];
|
|
218
218
|
const propertySchema = properties[propertyName];
|
|
219
219
|
const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
|
|
220
220
|
const nullable = propertySchema.nullable ?? propertySchema["x-nullable"] ?? false;
|
|
221
|
-
validationFunctions.push(...this.parse({
|
|
221
|
+
validationFunctions.push(...this.parse({ schemaObject: propertySchema, name: propertyName, parentName: name }));
|
|
222
222
|
validationFunctions.push({
|
|
223
223
|
keyword: schemaKeywords.name,
|
|
224
224
|
args: propertyName
|
|
@@ -234,7 +234,7 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
234
234
|
}).reduce((acc, curr) => ({ ...acc, ...curr }), {});
|
|
235
235
|
let additionalPropertiesSchemas = [];
|
|
236
236
|
if (additionalProperties) {
|
|
237
|
-
additionalPropertiesSchemas = additionalProperties === true || !Object.keys(additionalProperties).length ? [{ keyword: this.#getUnknownReturn({
|
|
237
|
+
additionalPropertiesSchemas = additionalProperties === true || !Object.keys(additionalProperties).length ? [{ keyword: this.#getUnknownReturn({ schemaObject, name }) }] : this.parse({ schemaObject: additionalProperties, parentName: name });
|
|
238
238
|
}
|
|
239
239
|
return [
|
|
240
240
|
{
|
|
@@ -249,23 +249,57 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
249
249
|
/**
|
|
250
250
|
* Create a type alias for the schema referenced by the given ReferenceObject
|
|
251
251
|
*/
|
|
252
|
-
#getRefAlias(
|
|
253
|
-
const { $ref } =
|
|
254
|
-
|
|
255
|
-
const originalName = utils.getUniqueName($ref.replace(/.+\//, ""), this.#usedAliasNames);
|
|
256
|
-
const propertyName = this.context.pluginManager.resolveName({
|
|
257
|
-
name: originalName,
|
|
258
|
-
pluginKey: this.context.plugin.key,
|
|
259
|
-
type: "function"
|
|
260
|
-
});
|
|
252
|
+
#getRefAlias(schemaObject, name) {
|
|
253
|
+
const { $ref } = schemaObject;
|
|
254
|
+
const ref = this.refs[$ref];
|
|
261
255
|
if (ref) {
|
|
256
|
+
const dereferencedSchema = this.context.oas.dereferenceWithRef(schemaObject);
|
|
257
|
+
if (dereferencedSchema && oas.isDiscriminator(dereferencedSchema)) {
|
|
258
|
+
const [key] = Object.entries(dereferencedSchema.discriminator.mapping || {}).find(([_key, value]) => value.replace(/.+\//, "") === name) || [];
|
|
259
|
+
if (key) {
|
|
260
|
+
return [
|
|
261
|
+
{
|
|
262
|
+
keyword: schemaKeywords.and,
|
|
263
|
+
args: [
|
|
264
|
+
{
|
|
265
|
+
keyword: schemaKeywords.ref,
|
|
266
|
+
args: { name: ref.propertyName, $ref, path: ref.path, isImportable: !!this.context.oas.get($ref) }
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
keyword: schemaKeywords.object,
|
|
270
|
+
args: {
|
|
271
|
+
properties: {
|
|
272
|
+
[dereferencedSchema.discriminator.propertyName]: [
|
|
273
|
+
{
|
|
274
|
+
keyword: schemaKeywords.const,
|
|
275
|
+
args: {
|
|
276
|
+
name: key,
|
|
277
|
+
format: "string",
|
|
278
|
+
value: key
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
]
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
];
|
|
288
|
+
}
|
|
289
|
+
}
|
|
262
290
|
return [
|
|
263
291
|
{
|
|
264
292
|
keyword: schemaKeywords.ref,
|
|
265
|
-
args: { name: ref.propertyName, path: ref.path, isImportable: !!this.context.oas.get($ref) }
|
|
293
|
+
args: { name: ref.propertyName, $ref, path: ref.path, isImportable: !!this.context.oas.get($ref) }
|
|
266
294
|
}
|
|
267
295
|
];
|
|
268
296
|
}
|
|
297
|
+
const originalName = utils.getUniqueName($ref.replace(/.+\//, ""), this.#usedAliasNames);
|
|
298
|
+
const propertyName = this.context.pluginManager.resolveName({
|
|
299
|
+
name: originalName,
|
|
300
|
+
pluginKey: this.context.plugin.key,
|
|
301
|
+
type: "function"
|
|
302
|
+
});
|
|
269
303
|
const fileName = this.context.pluginManager.resolveName({
|
|
270
304
|
name: originalName,
|
|
271
305
|
pluginKey: this.context.plugin.key,
|
|
@@ -276,73 +310,116 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
276
310
|
pluginKey: this.context.plugin.key,
|
|
277
311
|
extname: ".ts"
|
|
278
312
|
});
|
|
279
|
-
|
|
313
|
+
this.refs[$ref] = {
|
|
280
314
|
propertyName,
|
|
281
315
|
originalName,
|
|
282
316
|
path: file.path
|
|
283
317
|
};
|
|
284
|
-
return
|
|
285
|
-
{
|
|
286
|
-
keyword: schemaKeywords.ref,
|
|
287
|
-
args: { name: ref.propertyName, path: ref?.path, isImportable: !!this.context.oas.get($ref) }
|
|
288
|
-
}
|
|
289
|
-
];
|
|
318
|
+
return this.#getRefAlias(schemaObject, name);
|
|
290
319
|
}
|
|
291
320
|
#getParsedSchemaObject(schema) {
|
|
292
|
-
|
|
293
|
-
|
|
321
|
+
return chunkZVFL3NXX_cjs.getSchemaFactory(this.context.oas)(schema);
|
|
322
|
+
}
|
|
323
|
+
#addDiscriminatorToSchema({
|
|
324
|
+
schema,
|
|
325
|
+
schemaObject,
|
|
326
|
+
discriminator
|
|
327
|
+
}) {
|
|
328
|
+
if (!isKeyword(schema, schemaKeywords.union)) {
|
|
329
|
+
return schema;
|
|
330
|
+
}
|
|
331
|
+
const objectPropertySchema = _SchemaGenerator.find(this.parse({ schemaObject }), schemaKeywords.object);
|
|
332
|
+
return {
|
|
333
|
+
...schema,
|
|
334
|
+
args: schema.args.map((arg) => {
|
|
335
|
+
const isRef = isKeyword(arg, schemaKeywords.ref);
|
|
336
|
+
if (isRef) {
|
|
337
|
+
const [key] = Object.entries(discriminator.mapping || {}).find(([_key, value]) => value === arg.args.$ref) || [];
|
|
338
|
+
if (!key) {
|
|
339
|
+
throw new Error(`Can not find a key in discriminator ${JSON.stringify(schema)}`);
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
keyword: schemaKeywords.and,
|
|
343
|
+
args: [
|
|
344
|
+
arg,
|
|
345
|
+
{
|
|
346
|
+
keyword: schemaKeywords.object,
|
|
347
|
+
args: {
|
|
348
|
+
properties: {
|
|
349
|
+
...objectPropertySchema?.args?.properties || {},
|
|
350
|
+
[discriminator.propertyName]: [
|
|
351
|
+
{
|
|
352
|
+
keyword: schemaKeywords.const,
|
|
353
|
+
args: {
|
|
354
|
+
name: key,
|
|
355
|
+
format: "string",
|
|
356
|
+
value: key
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
//enum and literal will conflict
|
|
360
|
+
...objectPropertySchema?.args?.properties[discriminator.propertyName] || []
|
|
361
|
+
].filter((item) => !isKeyword(item, schemaKeywords.enum))
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
]
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return arg;
|
|
369
|
+
})
|
|
370
|
+
};
|
|
294
371
|
}
|
|
295
372
|
/**
|
|
296
373
|
* This is the very core of the OpenAPI to TS conversion - it takes a
|
|
297
374
|
* schema and returns the appropriate type.
|
|
298
375
|
*/
|
|
299
|
-
#parseSchemaObject({
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
const {
|
|
303
|
-
if (!
|
|
376
|
+
#parseSchemaObject({ schemaObject: _schemaObject, name, parentName }) {
|
|
377
|
+
const { schemaObject, version } = this.#getParsedSchemaObject(_schemaObject);
|
|
378
|
+
const options = this.#getOptions({ schemaObject, name });
|
|
379
|
+
const unknownReturn = this.#getUnknownReturn({ schemaObject, name });
|
|
380
|
+
if (!schemaObject) {
|
|
304
381
|
return [{ keyword: unknownReturn }];
|
|
305
382
|
}
|
|
306
383
|
const baseItems = [
|
|
307
384
|
{
|
|
308
385
|
keyword: schemaKeywords.schema,
|
|
309
386
|
args: {
|
|
310
|
-
type:
|
|
311
|
-
format:
|
|
387
|
+
type: schemaObject.type,
|
|
388
|
+
format: schemaObject.format
|
|
312
389
|
}
|
|
313
390
|
}
|
|
314
391
|
];
|
|
315
|
-
const min =
|
|
316
|
-
const max =
|
|
317
|
-
const nullable = oas.isNullable(
|
|
318
|
-
const defaultNullAndNullable =
|
|
319
|
-
if (
|
|
320
|
-
if (typeof
|
|
392
|
+
const min = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
|
|
393
|
+
const max = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
|
|
394
|
+
const nullable = oas.isNullable(schemaObject);
|
|
395
|
+
const defaultNullAndNullable = schemaObject.default === null && nullable;
|
|
396
|
+
if (schemaObject.default !== void 0 && !defaultNullAndNullable && !Array.isArray(schemaObject.default)) {
|
|
397
|
+
if (typeof schemaObject.default === "string") {
|
|
321
398
|
baseItems.push({
|
|
322
399
|
keyword: schemaKeywords.default,
|
|
323
|
-
args: transformers__default.default.stringify(
|
|
400
|
+
args: transformers__default.default.stringify(schemaObject.default)
|
|
324
401
|
});
|
|
325
|
-
} else if (typeof
|
|
402
|
+
} else if (typeof schemaObject.default === "boolean") {
|
|
326
403
|
baseItems.push({
|
|
327
404
|
keyword: schemaKeywords.default,
|
|
328
|
-
args:
|
|
405
|
+
args: schemaObject.default ?? false
|
|
329
406
|
});
|
|
330
407
|
} else {
|
|
331
408
|
baseItems.push({
|
|
332
409
|
keyword: schemaKeywords.default,
|
|
333
|
-
args:
|
|
410
|
+
args: schemaObject.default
|
|
334
411
|
});
|
|
335
412
|
}
|
|
336
413
|
}
|
|
337
|
-
if (
|
|
414
|
+
if (schemaObject.deprecated) {
|
|
338
415
|
baseItems.push({
|
|
339
416
|
keyword: schemaKeywords.deprecated
|
|
340
417
|
});
|
|
341
418
|
}
|
|
342
|
-
if (
|
|
419
|
+
if (schemaObject.description) {
|
|
343
420
|
baseItems.push({
|
|
344
421
|
keyword: schemaKeywords.describe,
|
|
345
|
-
args:
|
|
422
|
+
args: schemaObject.description
|
|
346
423
|
});
|
|
347
424
|
}
|
|
348
425
|
if (max !== void 0) {
|
|
@@ -354,49 +431,51 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
354
431
|
if (nullable) {
|
|
355
432
|
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
356
433
|
}
|
|
357
|
-
if (
|
|
358
|
-
const [
|
|
434
|
+
if (schemaObject.type && Array.isArray(schemaObject.type)) {
|
|
435
|
+
const [_schema, nullable2] = schemaObject.type;
|
|
359
436
|
if (nullable2 === "null") {
|
|
360
437
|
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
361
438
|
}
|
|
362
439
|
}
|
|
363
|
-
if (
|
|
440
|
+
if (schemaObject.readOnly) {
|
|
364
441
|
baseItems.push({ keyword: schemaKeywords.readOnly });
|
|
365
442
|
}
|
|
366
|
-
if (
|
|
443
|
+
if (schemaObject.writeOnly) {
|
|
367
444
|
baseItems.push({ keyword: schemaKeywords.writeOnly });
|
|
368
445
|
}
|
|
369
|
-
if (oas.isReference(
|
|
446
|
+
if (oas.isReference(schemaObject)) {
|
|
370
447
|
return [
|
|
371
|
-
...this.#getRefAlias(
|
|
372
|
-
|
|
448
|
+
...this.#getRefAlias(schemaObject, name),
|
|
449
|
+
schemaObject.description && {
|
|
373
450
|
keyword: schemaKeywords.describe,
|
|
374
|
-
args:
|
|
451
|
+
args: schemaObject.description
|
|
375
452
|
},
|
|
376
453
|
nullable && { keyword: schemaKeywords.nullable },
|
|
377
|
-
|
|
378
|
-
|
|
454
|
+
schemaObject.readOnly && { keyword: schemaKeywords.readOnly },
|
|
455
|
+
schemaObject.writeOnly && { keyword: schemaKeywords.writeOnly },
|
|
379
456
|
{
|
|
380
457
|
keyword: schemaKeywords.schema,
|
|
381
458
|
args: {
|
|
382
|
-
type:
|
|
383
|
-
format:
|
|
459
|
+
type: schemaObject.type,
|
|
460
|
+
format: schemaObject.format
|
|
384
461
|
}
|
|
385
462
|
}
|
|
386
463
|
].filter(Boolean);
|
|
387
464
|
}
|
|
388
|
-
if (
|
|
389
|
-
const schemaWithoutOneOf = { ...
|
|
465
|
+
if (schemaObject.oneOf) {
|
|
466
|
+
const schemaWithoutOneOf = { ...schemaObject, oneOf: void 0 };
|
|
390
467
|
const union = {
|
|
391
468
|
keyword: schemaKeywords.union,
|
|
392
|
-
args:
|
|
393
|
-
return item && this.parse({
|
|
394
|
-
}).filter(Boolean).filter((item) =>
|
|
395
|
-
return item && item.keyword !== unknownReturn;
|
|
396
|
-
})
|
|
469
|
+
args: schemaObject.oneOf.map((item) => {
|
|
470
|
+
return item && this.parse({ schemaObject: item, name, parentName })[0];
|
|
471
|
+
}).filter(Boolean).filter((item) => !isKeyword(item, schemaKeywords.unknown))
|
|
397
472
|
};
|
|
473
|
+
const discriminator = this.context.oas.getDiscriminator(schemaObject);
|
|
474
|
+
if (discriminator) {
|
|
475
|
+
return [this.#addDiscriminatorToSchema({ schemaObject: schemaWithoutOneOf, schema: union, discriminator }), ...baseItems];
|
|
476
|
+
}
|
|
398
477
|
if (schemaWithoutOneOf.properties) {
|
|
399
|
-
const propertySchemas = this.parse({
|
|
478
|
+
const propertySchemas = this.parse({ schemaObject: schemaWithoutOneOf, name, parentName });
|
|
400
479
|
union.args = [
|
|
401
480
|
...union.args.map((arg) => {
|
|
402
481
|
return {
|
|
@@ -405,18 +484,17 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
405
484
|
};
|
|
406
485
|
})
|
|
407
486
|
];
|
|
487
|
+
return [union, ...baseItems];
|
|
408
488
|
}
|
|
409
489
|
return [union, ...baseItems];
|
|
410
490
|
}
|
|
411
|
-
if (
|
|
412
|
-
const schemaWithoutAnyOf = { ...
|
|
491
|
+
if (schemaObject.anyOf) {
|
|
492
|
+
const schemaWithoutAnyOf = { ...schemaObject, anyOf: void 0 };
|
|
413
493
|
const union = {
|
|
414
494
|
keyword: schemaKeywords.union,
|
|
415
|
-
args:
|
|
416
|
-
return item && this.parse({
|
|
417
|
-
}).filter(Boolean).filter((item) => {
|
|
418
|
-
return item && item.keyword !== unknownReturn;
|
|
419
|
-
}).map((item) => {
|
|
495
|
+
args: schemaObject.anyOf.map((item) => {
|
|
496
|
+
return item && this.parse({ schemaObject: item, name, parentName })[0];
|
|
497
|
+
}).filter(Boolean).filter((item) => !isKeyword(item, schemaKeywords.unknown)).map((item) => {
|
|
420
498
|
if (isKeyword(item, schemaKeywords.object)) {
|
|
421
499
|
return {
|
|
422
500
|
...item,
|
|
@@ -429,23 +507,34 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
429
507
|
return item;
|
|
430
508
|
})
|
|
431
509
|
};
|
|
510
|
+
const discriminator = this.context.oas.getDiscriminator(schemaObject);
|
|
511
|
+
if (discriminator) {
|
|
512
|
+
return [this.#addDiscriminatorToSchema({ schemaObject: schemaWithoutAnyOf, schema: union, discriminator }), ...baseItems];
|
|
513
|
+
}
|
|
432
514
|
if (schemaWithoutAnyOf.properties) {
|
|
433
|
-
|
|
515
|
+
const propertySchemas = this.parse({ schemaObject: schemaWithoutAnyOf, name, parentName });
|
|
516
|
+
union.args = [
|
|
517
|
+
...union.args.map((arg) => {
|
|
518
|
+
return {
|
|
519
|
+
keyword: schemaKeywords.and,
|
|
520
|
+
args: [arg, ...propertySchemas]
|
|
521
|
+
};
|
|
522
|
+
})
|
|
523
|
+
];
|
|
524
|
+
return [union, ...baseItems];
|
|
434
525
|
}
|
|
435
526
|
return [union, ...baseItems];
|
|
436
527
|
}
|
|
437
|
-
if (
|
|
438
|
-
const schemaWithoutAllOf = { ...
|
|
528
|
+
if (schemaObject.allOf) {
|
|
529
|
+
const schemaWithoutAllOf = { ...schemaObject, allOf: void 0 };
|
|
439
530
|
const and = {
|
|
440
531
|
keyword: schemaKeywords.and,
|
|
441
|
-
args:
|
|
442
|
-
return item && this.parse({
|
|
443
|
-
}).filter(Boolean).filter((item) =>
|
|
444
|
-
return item && item.keyword !== unknownReturn;
|
|
445
|
-
})
|
|
532
|
+
args: schemaObject.allOf.map((item) => {
|
|
533
|
+
return item && this.parse({ schemaObject: item, name, parentName })[0];
|
|
534
|
+
}).filter(Boolean).filter((item) => !isKeyword(item, schemaKeywords.unknown))
|
|
446
535
|
};
|
|
447
536
|
if (schemaWithoutAllOf.required) {
|
|
448
|
-
const schemas =
|
|
537
|
+
const schemas = schemaObject.allOf.map((item) => {
|
|
449
538
|
if (oas.isReference(item)) {
|
|
450
539
|
return this.context.oas.get(item.$ref);
|
|
451
540
|
}
|
|
@@ -456,40 +545,40 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
456
545
|
}
|
|
457
546
|
return true;
|
|
458
547
|
}).map((key) => {
|
|
459
|
-
const
|
|
460
|
-
if (
|
|
548
|
+
const schema = schemas.find((item) => item.properties && Object.keys(item.properties).find((propertyKey) => propertyKey === key));
|
|
549
|
+
if (schema?.properties?.[key]) {
|
|
461
550
|
return {
|
|
462
|
-
...
|
|
551
|
+
...schema,
|
|
463
552
|
properties: {
|
|
464
|
-
[key]:
|
|
553
|
+
[key]: schema.properties[key]
|
|
465
554
|
},
|
|
466
555
|
required: [key]
|
|
467
556
|
};
|
|
468
557
|
}
|
|
469
558
|
}).filter(Boolean);
|
|
470
|
-
and.args = [...and.args || [], ...items.flatMap((item) => this.parse({
|
|
559
|
+
and.args = [...and.args || [], ...items.flatMap((item) => this.parse({ schemaObject: item, name, parentName }))];
|
|
471
560
|
}
|
|
472
561
|
if (schemaWithoutAllOf.properties) {
|
|
473
|
-
and.args = [...and.args || [], ...this.parse({
|
|
562
|
+
and.args = [...and.args || [], ...this.parse({ schemaObject: schemaWithoutAllOf, name, parentName })];
|
|
474
563
|
}
|
|
475
564
|
return [and, ...baseItems];
|
|
476
565
|
}
|
|
477
|
-
if (
|
|
566
|
+
if (schemaObject.enum) {
|
|
478
567
|
if (options.enumSuffix === "") {
|
|
479
|
-
|
|
568
|
+
this.context.pluginManager.logger.emit("info", "EnumSuffix set to an empty string does not work");
|
|
480
569
|
}
|
|
481
|
-
const enumName = utils.getUniqueName(transformers.pascalCase([parentName, name, options.enumSuffix].join(" ")), this.#getUsedEnumNames({
|
|
570
|
+
const enumName = utils.getUniqueName(transformers.pascalCase([parentName, name, options.enumSuffix].join(" ")), this.#getUsedEnumNames({ schemaObject, name }));
|
|
482
571
|
const typeName = this.context.pluginManager.resolveName({
|
|
483
572
|
name: enumName,
|
|
484
573
|
pluginKey: this.context.plugin.key,
|
|
485
574
|
type: "type"
|
|
486
575
|
});
|
|
487
|
-
const nullableEnum =
|
|
576
|
+
const nullableEnum = schemaObject.enum.includes(null);
|
|
488
577
|
if (nullableEnum) {
|
|
489
578
|
baseItems.push({ keyword: schemaKeywords.nullable });
|
|
490
579
|
}
|
|
491
|
-
const filteredValues =
|
|
492
|
-
const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in
|
|
580
|
+
const filteredValues = schemaObject.enum.filter((value) => value !== null);
|
|
581
|
+
const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schemaObject).map((extensionKey) => {
|
|
493
582
|
return [
|
|
494
583
|
{
|
|
495
584
|
keyword: schemaKeywords.enum,
|
|
@@ -497,10 +586,10 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
497
586
|
name,
|
|
498
587
|
typeName,
|
|
499
588
|
asConst: false,
|
|
500
|
-
items: [...new Set(
|
|
589
|
+
items: [...new Set(schemaObject[extensionKey])].map((name2, index) => ({
|
|
501
590
|
name: transformers__default.default.stringify(name2),
|
|
502
|
-
value:
|
|
503
|
-
format: remeda.isNumber(
|
|
591
|
+
value: schemaObject.enum?.[index],
|
|
592
|
+
format: remeda.isNumber(schemaObject.enum?.[index]) ? "number" : "string"
|
|
504
593
|
}))
|
|
505
594
|
}
|
|
506
595
|
},
|
|
@@ -509,7 +598,7 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
509
598
|
)
|
|
510
599
|
];
|
|
511
600
|
});
|
|
512
|
-
if (
|
|
601
|
+
if (schemaObject.type === "number" || schemaObject.type === "integer") {
|
|
513
602
|
const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
|
|
514
603
|
return [
|
|
515
604
|
{
|
|
@@ -534,7 +623,7 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
534
623
|
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
|
|
535
624
|
];
|
|
536
625
|
}
|
|
537
|
-
if (
|
|
626
|
+
if (schemaObject.type === "boolean") {
|
|
538
627
|
const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
|
|
539
628
|
return [
|
|
540
629
|
{
|
|
@@ -579,10 +668,10 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
579
668
|
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
|
|
580
669
|
];
|
|
581
670
|
}
|
|
582
|
-
if ("prefixItems" in
|
|
583
|
-
const prefixItems =
|
|
584
|
-
const min2 =
|
|
585
|
-
const max2 =
|
|
671
|
+
if ("prefixItems" in schemaObject) {
|
|
672
|
+
const prefixItems = schemaObject.prefixItems;
|
|
673
|
+
const min2 = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
|
|
674
|
+
const max2 = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
|
|
586
675
|
return [
|
|
587
676
|
{
|
|
588
677
|
keyword: schemaKeywords.tuple,
|
|
@@ -590,22 +679,22 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
590
679
|
min: min2,
|
|
591
680
|
max: max2,
|
|
592
681
|
items: prefixItems.map((item) => {
|
|
593
|
-
return this.parse({
|
|
682
|
+
return this.parse({ schemaObject: item, name, parentName })[0];
|
|
594
683
|
}).filter(Boolean)
|
|
595
684
|
}
|
|
596
685
|
},
|
|
597
686
|
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
|
|
598
687
|
];
|
|
599
688
|
}
|
|
600
|
-
if (version === "3.1" && "const" in
|
|
601
|
-
if (
|
|
689
|
+
if (version === "3.1" && "const" in schemaObject) {
|
|
690
|
+
if (schemaObject["const"]) {
|
|
602
691
|
return [
|
|
603
692
|
{
|
|
604
693
|
keyword: schemaKeywords.const,
|
|
605
694
|
args: {
|
|
606
|
-
name:
|
|
607
|
-
format: typeof
|
|
608
|
-
value:
|
|
695
|
+
name: schemaObject["const"],
|
|
696
|
+
format: typeof schemaObject["const"] === "number" ? "number" : "string",
|
|
697
|
+
value: schemaObject["const"]
|
|
609
698
|
}
|
|
610
699
|
},
|
|
611
700
|
...baseItems
|
|
@@ -613,8 +702,8 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
613
702
|
}
|
|
614
703
|
return [{ keyword: schemaKeywords.null }];
|
|
615
704
|
}
|
|
616
|
-
if (
|
|
617
|
-
switch (
|
|
705
|
+
if (schemaObject.format) {
|
|
706
|
+
switch (schemaObject.format) {
|
|
618
707
|
case "binary":
|
|
619
708
|
baseItems.push({ keyword: schemaKeywords.blob });
|
|
620
709
|
return baseItems;
|
|
@@ -673,18 +762,18 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
673
762
|
return baseItems;
|
|
674
763
|
}
|
|
675
764
|
}
|
|
676
|
-
if (
|
|
765
|
+
if (schemaObject.pattern) {
|
|
677
766
|
baseItems.unshift({
|
|
678
767
|
keyword: schemaKeywords.matches,
|
|
679
|
-
args:
|
|
768
|
+
args: schemaObject.pattern
|
|
680
769
|
});
|
|
681
770
|
return baseItems;
|
|
682
771
|
}
|
|
683
|
-
if ("items" in
|
|
684
|
-
const min2 =
|
|
685
|
-
const max2 =
|
|
686
|
-
const items = this.parse({
|
|
687
|
-
const unique = !!
|
|
772
|
+
if ("items" in schemaObject || schemaObject.type === "array") {
|
|
773
|
+
const min2 = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
|
|
774
|
+
const max2 = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
|
|
775
|
+
const items = this.parse({ schemaObject: "items" in schemaObject ? schemaObject.items : [], name, parentName });
|
|
776
|
+
const unique = !!schemaObject.uniqueItems;
|
|
688
777
|
return [
|
|
689
778
|
{
|
|
690
779
|
keyword: schemaKeywords.array,
|
|
@@ -698,16 +787,40 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
698
787
|
...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
|
|
699
788
|
];
|
|
700
789
|
}
|
|
701
|
-
if (
|
|
702
|
-
|
|
790
|
+
if (schemaObject.properties || schemaObject.additionalProperties) {
|
|
791
|
+
if (oas.isDiscriminator(schemaObject)) {
|
|
792
|
+
const schemaObjectOverriden = Object.keys(schemaObject.properties || {}).reduce((acc, propertyName) => {
|
|
793
|
+
if (acc.properties?.[propertyName] && propertyName === schemaObject.discriminator.propertyName) {
|
|
794
|
+
return {
|
|
795
|
+
...acc,
|
|
796
|
+
properties: {
|
|
797
|
+
...acc.properties,
|
|
798
|
+
[propertyName]: {
|
|
799
|
+
...acc.properties[propertyName] || {},
|
|
800
|
+
enum: schemaObject.discriminator.mapping ? Object.keys(schemaObject.discriminator.mapping) : void 0
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
return acc;
|
|
806
|
+
}, schemaObject || {});
|
|
807
|
+
return [
|
|
808
|
+
...this.#parseProperties({
|
|
809
|
+
schemaObject: schemaObjectOverriden,
|
|
810
|
+
name
|
|
811
|
+
}),
|
|
812
|
+
...baseItems
|
|
813
|
+
];
|
|
814
|
+
}
|
|
815
|
+
return [...this.#parseProperties({ schemaObject, name }), ...baseItems];
|
|
703
816
|
}
|
|
704
|
-
if (
|
|
705
|
-
if (Array.isArray(
|
|
706
|
-
const [type] =
|
|
817
|
+
if (schemaObject.type) {
|
|
818
|
+
if (Array.isArray(schemaObject.type)) {
|
|
819
|
+
const [type] = schemaObject.type;
|
|
707
820
|
return [
|
|
708
821
|
...this.parse({
|
|
709
|
-
|
|
710
|
-
...
|
|
822
|
+
schemaObject: {
|
|
823
|
+
...schemaObject,
|
|
711
824
|
type
|
|
712
825
|
},
|
|
713
826
|
name,
|
|
@@ -716,17 +829,16 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
716
829
|
...baseItems
|
|
717
830
|
].filter(Boolean);
|
|
718
831
|
}
|
|
719
|
-
if (!["boolean", "object", "number", "string", "integer", "null"].includes(
|
|
720
|
-
this.context.pluginManager.logger.emit("warning", `Schema type '${
|
|
832
|
+
if (!["boolean", "object", "number", "string", "integer", "null"].includes(schemaObject.type)) {
|
|
833
|
+
this.context.pluginManager.logger.emit("warning", `Schema type '${schemaObject.type}' is not valid for schema ${parentName}.${name}`);
|
|
721
834
|
}
|
|
722
|
-
return [{ keyword:
|
|
835
|
+
return [{ keyword: schemaObject.type }, ...baseItems];
|
|
723
836
|
}
|
|
724
837
|
return [{ keyword: unknownReturn }];
|
|
725
838
|
}
|
|
726
839
|
async build(...generators) {
|
|
727
840
|
const { oas, contentType, include } = this.context;
|
|
728
|
-
|
|
729
|
-
const schemas = chunkB7KP5ZFA_cjs.getSchemas({ oas, contentType, includes: include });
|
|
841
|
+
const schemas = chunkZVFL3NXX_cjs.getSchemas({ oas, contentType, includes: include });
|
|
730
842
|
const promises = Object.entries(schemas).reduce((acc, [name, value]) => {
|
|
731
843
|
if (!value) {
|
|
732
844
|
return acc;
|
|
@@ -740,7 +852,7 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
740
852
|
acc.push(promiseOperation);
|
|
741
853
|
}
|
|
742
854
|
generators?.forEach((generator) => {
|
|
743
|
-
const tree = this.parse({
|
|
855
|
+
const tree = this.parse({ schemaObject: value, name });
|
|
744
856
|
const promise = generator.schema?.({
|
|
745
857
|
instance: this,
|
|
746
858
|
schema: {
|
|
@@ -773,5 +885,5 @@ var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
|
|
|
773
885
|
exports.SchemaGenerator = SchemaGenerator;
|
|
774
886
|
exports.isKeyword = isKeyword;
|
|
775
887
|
exports.schemaKeywords = schemaKeywords;
|
|
776
|
-
//# sourceMappingURL=chunk-
|
|
777
|
-
//# sourceMappingURL=chunk-
|
|
888
|
+
//# sourceMappingURL=chunk-PSWNN6SJ.cjs.map
|
|
889
|
+
//# sourceMappingURL=chunk-PSWNN6SJ.cjs.map
|