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