@kubb/plugin-oas 3.10.2 → 3.10.4

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.
Files changed (56) hide show
  1. package/dist/{OperationGenerator-DiF6WJNP.d.cts → OperationGenerator-BrnQyed_.d.cts} +9 -1
  2. package/dist/{OperationGenerator-DiF6WJNP.d.ts → OperationGenerator-BrnQyed_.d.ts} +9 -1
  3. package/dist/Schema-DTc2F3jG.d.cts +32 -0
  4. package/dist/Schema-Dhz38Get.d.ts +32 -0
  5. package/dist/{chunk-72MVTXCW.js → chunk-5JWN6NVC.js} +245 -133
  6. package/dist/chunk-5JWN6NVC.js.map +1 -0
  7. package/dist/{chunk-DUZZHEQI.cjs → chunk-ES7R7N34.cjs} +6 -6
  8. package/dist/chunk-ES7R7N34.cjs.map +1 -0
  9. package/dist/{chunk-BAU7PO7T.js → chunk-JNN4JPWK.js} +4 -4
  10. package/dist/chunk-JNN4JPWK.js.map +1 -0
  11. package/dist/{chunk-3Y4QGY6D.js → chunk-PORSNYI5.js} +3 -3
  12. package/dist/chunk-PORSNYI5.js.map +1 -0
  13. package/dist/{chunk-Q4HTTWL7.cjs → chunk-PSWNN6SJ.cjs} +245 -133
  14. package/dist/chunk-PSWNN6SJ.cjs.map +1 -0
  15. package/dist/{chunk-DN373TFU.js → chunk-RNF2QJEG.js} +4 -4
  16. package/dist/chunk-RNF2QJEG.js.map +1 -0
  17. package/dist/{chunk-KXB5DUFD.cjs → chunk-Z2NREI4X.cjs} +4 -4
  18. package/dist/chunk-Z2NREI4X.cjs.map +1 -0
  19. package/dist/{chunk-B7KP5ZFA.cjs → chunk-ZVFL3NXX.cjs} +3 -3
  20. package/dist/chunk-ZVFL3NXX.cjs.map +1 -0
  21. package/dist/components.cjs +4 -4
  22. package/dist/components.d.cts +2 -2
  23. package/dist/components.d.ts +2 -2
  24. package/dist/components.js +1 -1
  25. package/dist/generators.cjs +4 -4
  26. package/dist/generators.d.cts +1 -1
  27. package/dist/generators.d.ts +1 -1
  28. package/dist/generators.js +3 -3
  29. package/dist/hooks.cjs +9 -9
  30. package/dist/hooks.d.cts +2 -2
  31. package/dist/hooks.d.ts +2 -2
  32. package/dist/hooks.js +3 -3
  33. package/dist/index.cjs +11 -11
  34. package/dist/index.d.cts +2 -2
  35. package/dist/index.d.ts +2 -2
  36. package/dist/index.js +6 -6
  37. package/dist/utils.cjs +3 -3
  38. package/dist/utils.d.cts +10 -3
  39. package/dist/utils.d.ts +10 -3
  40. package/dist/utils.js +1 -1
  41. package/package.json +7 -7
  42. package/src/SchemaGenerator.ts +271 -132
  43. package/src/SchemaMapper.ts +1 -0
  44. package/src/components/Schema.tsx +13 -4
  45. package/src/generator.tsx +8 -1
  46. package/src/utils/getSchemaFactory.ts +10 -3
  47. package/dist/Schema-BbIxCfn7.d.ts +0 -23
  48. package/dist/Schema-Ds5f4y7m.d.cts +0 -23
  49. package/dist/chunk-3Y4QGY6D.js.map +0 -1
  50. package/dist/chunk-72MVTXCW.js.map +0 -1
  51. package/dist/chunk-B7KP5ZFA.cjs.map +0 -1
  52. package/dist/chunk-BAU7PO7T.js.map +0 -1
  53. package/dist/chunk-DN373TFU.js.map +0 -1
  54. package/dist/chunk-DUZZHEQI.cjs.map +0 -1
  55. package/dist/chunk-KXB5DUFD.cjs.map +0 -1
  56. package/dist/chunk-Q4HTTWL7.cjs.map +0 -1
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkB7KP5ZFA_cjs = require('./chunk-B7KP5ZFA.cjs');
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({ schema, name }) {
213
- const properties = schema?.properties || {};
214
- const additionalProperties = schema?.additionalProperties;
215
- const required = schema?.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({ schema: propertySchema, name: propertyName, parentName: name }));
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({ schema, name }) }] : this.parse({ schema: additionalProperties, parentName: name });
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(obj) {
253
- const { $ref } = obj;
254
- let ref = this.refs[$ref];
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
- ref = this.refs[$ref] = {
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
- const parsedSchema = chunkB7KP5ZFA_cjs.getSchemaFactory(this.context.oas)(schema);
293
- return parsedSchema;
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({ schema: _schema, name, parentName }) {
300
- const options = this.#getOptions({ schema: _schema, name });
301
- const unknownReturn = this.#getUnknownReturn({ schema: _schema, name });
302
- const { schema, version } = this.#getParsedSchemaObject(_schema);
303
- if (!schema) {
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: schema.type,
311
- format: schema.format
387
+ type: schemaObject.type,
388
+ format: schemaObject.format
312
389
  }
313
390
  }
314
391
  ];
315
- const min = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
316
- const max = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
317
- const nullable = oas.isNullable(schema);
318
- const defaultNullAndNullable = schema.default === null && nullable;
319
- if (schema.default !== void 0 && !defaultNullAndNullable && !Array.isArray(schema.default)) {
320
- if (typeof schema.default === "string") {
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(schema.default)
400
+ args: transformers__default.default.stringify(schemaObject.default)
324
401
  });
325
- } else if (typeof schema.default === "boolean") {
402
+ } else if (typeof schemaObject.default === "boolean") {
326
403
  baseItems.push({
327
404
  keyword: schemaKeywords.default,
328
- args: schema.default ?? false
405
+ args: schemaObject.default ?? false
329
406
  });
330
407
  } else {
331
408
  baseItems.push({
332
409
  keyword: schemaKeywords.default,
333
- args: schema.default
410
+ args: schemaObject.default
334
411
  });
335
412
  }
336
413
  }
337
- if (schema.deprecated) {
414
+ if (schemaObject.deprecated) {
338
415
  baseItems.push({
339
416
  keyword: schemaKeywords.deprecated
340
417
  });
341
418
  }
342
- if (schema.description) {
419
+ if (schemaObject.description) {
343
420
  baseItems.push({
344
421
  keyword: schemaKeywords.describe,
345
- args: schema.description
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 (schema.type && Array.isArray(schema.type)) {
358
- const [_schema2, nullable2] = schema.type;
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 (schema.readOnly) {
440
+ if (schemaObject.readOnly) {
364
441
  baseItems.push({ keyword: schemaKeywords.readOnly });
365
442
  }
366
- if (schema.writeOnly) {
443
+ if (schemaObject.writeOnly) {
367
444
  baseItems.push({ keyword: schemaKeywords.writeOnly });
368
445
  }
369
- if (oas.isReference(schema)) {
446
+ if (oas.isReference(schemaObject)) {
370
447
  return [
371
- ...this.#getRefAlias(schema),
372
- schema.description && {
448
+ ...this.#getRefAlias(schemaObject, name),
449
+ schemaObject.description && {
373
450
  keyword: schemaKeywords.describe,
374
- args: schema.description
451
+ args: schemaObject.description
375
452
  },
376
453
  nullable && { keyword: schemaKeywords.nullable },
377
- schema.readOnly && { keyword: schemaKeywords.readOnly },
378
- schema.writeOnly && { keyword: schemaKeywords.writeOnly },
454
+ schemaObject.readOnly && { keyword: schemaKeywords.readOnly },
455
+ schemaObject.writeOnly && { keyword: schemaKeywords.writeOnly },
379
456
  {
380
457
  keyword: schemaKeywords.schema,
381
458
  args: {
382
- type: schema.type,
383
- format: schema.format
459
+ type: schemaObject.type,
460
+ format: schemaObject.format
384
461
  }
385
462
  }
386
463
  ].filter(Boolean);
387
464
  }
388
- if (schema.oneOf) {
389
- const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
465
+ if (schemaObject.oneOf) {
466
+ const schemaWithoutOneOf = { ...schemaObject, oneOf: void 0 };
390
467
  const union = {
391
468
  keyword: schemaKeywords.union,
392
- args: schema.oneOf.map((item) => {
393
- return item && this.parse({ schema: item, name, parentName })[0];
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({ schema: schemaWithoutOneOf, name, parentName });
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 (schema.anyOf) {
412
- const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
491
+ if (schemaObject.anyOf) {
492
+ const schemaWithoutAnyOf = { ...schemaObject, anyOf: void 0 };
413
493
  const union = {
414
494
  keyword: schemaKeywords.union,
415
- args: schema.anyOf.map((item) => {
416
- return item && this.parse({ schema: item, name, parentName })[0];
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
- return [...this.parse({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems];
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 (schema.allOf) {
438
- const schemaWithoutAllOf = { ...schema, allOf: void 0 };
528
+ if (schemaObject.allOf) {
529
+ const schemaWithoutAllOf = { ...schemaObject, allOf: void 0 };
439
530
  const and = {
440
531
  keyword: schemaKeywords.and,
441
- args: schema.allOf.map((item) => {
442
- return item && this.parse({ schema: item, name, parentName })[0];
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 = schema.allOf.map((item) => {
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 schema2 = schemas.find((item) => item.properties && Object.keys(item.properties).find((propertyKey) => propertyKey === key));
460
- if (schema2?.properties?.[key]) {
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
- ...schema2,
551
+ ...schema,
463
552
  properties: {
464
- [key]: schema2.properties[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({ schema: item, name, parentName }))];
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({ schema: schemaWithoutAllOf, name, parentName })];
562
+ and.args = [...and.args || [], ...this.parse({ schemaObject: schemaWithoutAllOf, name, parentName })];
474
563
  }
475
564
  return [and, ...baseItems];
476
565
  }
477
- if (schema.enum) {
566
+ if (schemaObject.enum) {
478
567
  if (options.enumSuffix === "") {
479
- throw new Error("EnumSuffix set to an empty string does not work");
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({ schema, name }));
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 = schema.enum.includes(null);
576
+ const nullableEnum = schemaObject.enum.includes(null);
488
577
  if (nullableEnum) {
489
578
  baseItems.push({ keyword: schemaKeywords.nullable });
490
579
  }
491
- const filteredValues = schema.enum.filter((value) => value !== null);
492
- const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map((extensionKey) => {
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(schema[extensionKey])].map((name2, index) => ({
589
+ items: [...new Set(schemaObject[extensionKey])].map((name2, index) => ({
501
590
  name: transformers__default.default.stringify(name2),
502
- value: schema.enum?.[index],
503
- format: remeda.isNumber(schema.enum?.[index]) ? "number" : "string"
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 (schema.type === "number" || schema.type === "integer") {
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 (schema.type === "boolean") {
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 schema) {
583
- const prefixItems = schema.prefixItems;
584
- const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
585
- const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
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({ schema: item, name, parentName })[0];
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 schema) {
601
- if (schema["const"]) {
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: schema["const"],
607
- format: typeof schema["const"] === "number" ? "number" : "string",
608
- value: schema["const"]
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 (schema.format) {
617
- switch (schema.format) {
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 (schema.pattern) {
765
+ if (schemaObject.pattern) {
677
766
  baseItems.unshift({
678
767
  keyword: schemaKeywords.matches,
679
- args: schema.pattern
768
+ args: schemaObject.pattern
680
769
  });
681
770
  return baseItems;
682
771
  }
683
- if ("items" in schema || schema.type === "array") {
684
- const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
685
- const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
686
- const items = this.parse({ schema: "items" in schema ? schema.items : [], name, parentName });
687
- const unique = !!schema.uniqueItems;
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 (schema.properties || schema.additionalProperties) {
702
- return [...this.#parseProperties({ schema, name }), ...baseItems];
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 (schema.type) {
705
- if (Array.isArray(schema.type)) {
706
- const [type] = schema.type;
817
+ if (schemaObject.type) {
818
+ if (Array.isArray(schemaObject.type)) {
819
+ const [type] = schemaObject.type;
707
820
  return [
708
821
  ...this.parse({
709
- schema: {
710
- ...schema,
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(schema.type)) {
720
- this.context.pluginManager.logger.emit("warning", `Schema type '${schema.type}' is not valid for schema ${parentName}.${name}`);
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: schema.type }, ...baseItems];
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
- oas.resolveDiscriminators();
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({ schema: value, name });
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-Q4HTTWL7.cjs.map
777
- //# sourceMappingURL=chunk-Q4HTTWL7.cjs.map
888
+ //# sourceMappingURL=chunk-PSWNN6SJ.cjs.map
889
+ //# sourceMappingURL=chunk-PSWNN6SJ.cjs.map