@kubb/plugin-oas 3.0.0-alpha.6 → 3.0.0-alpha.8

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 (58) hide show
  1. package/dist/{OperationGenerator-Dzs1oRvm.d.ts → OperationGenerator-DeXrfGDC.d.ts} +2 -2
  2. package/dist/{OperationGenerator-Do52cvD0.d.cts → OperationGenerator-DhJ0MBKc.d.cts} +2 -2
  3. package/dist/{Schema-C90zFdkU.d.ts → Schema-B1vcPGiK.d.ts} +2 -4
  4. package/dist/{Schema-DDVEcNcu.d.cts → Schema-DoSFh7Qd.d.cts} +2 -4
  5. package/dist/{SchemaMapper-BM1IGWqD.d.cts → SchemaMapper-sGcY1xL5.d.cts} +0 -1
  6. package/dist/{SchemaMapper-BM1IGWqD.d.ts → SchemaMapper-sGcY1xL5.d.ts} +0 -1
  7. package/dist/chunk-75BIOXB7.cjs +7 -0
  8. package/dist/{chunk-7KIEQOVZ.cjs.map → chunk-75BIOXB7.cjs.map} +1 -1
  9. package/dist/{chunk-UJNAXXVE.js → chunk-MUI5DWM3.js} +458 -465
  10. package/dist/{chunk-UJNAXXVE.js.map → chunk-MUI5DWM3.js.map} +1 -1
  11. package/dist/{chunk-Y4V7HHX7.js → chunk-N7EEVJA6.js} +3 -3
  12. package/dist/{chunk-P42X362U.cjs → chunk-NU4F7G47.cjs} +4 -16
  13. package/dist/chunk-NU4F7G47.cjs.map +1 -0
  14. package/dist/{chunk-QLJIL3U5.cjs → chunk-O76YQFZB.cjs} +3 -3
  15. package/dist/{chunk-QLJIL3U5.cjs.map → chunk-O76YQFZB.cjs.map} +1 -1
  16. package/dist/{chunk-TWKZEVSM.js → chunk-SQ64ESS4.js} +2 -2
  17. package/dist/{chunk-UB552H4J.js → chunk-SZDO532A.js} +3 -15
  18. package/dist/{chunk-UB552H4J.js.map → chunk-SZDO532A.js.map} +1 -1
  19. package/dist/{chunk-RQZBFORW.cjs → chunk-VSVVTCQB.cjs} +481 -488
  20. package/dist/chunk-VSVVTCQB.cjs.map +1 -0
  21. package/dist/components.cjs +4 -4
  22. package/dist/components.d.cts +4 -4
  23. package/dist/components.d.ts +4 -4
  24. package/dist/components.js +3 -3
  25. package/dist/hooks.cjs +12 -12
  26. package/dist/hooks.cjs.map +1 -1
  27. package/dist/hooks.d.cts +3 -3
  28. package/dist/hooks.d.ts +3 -3
  29. package/dist/hooks.js +2 -2
  30. package/dist/hooks.js.map +1 -1
  31. package/dist/index.cjs +112 -115
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.d.cts +4 -4
  34. package/dist/index.d.ts +4 -4
  35. package/dist/index.js +83 -86
  36. package/dist/index.js.map +1 -1
  37. package/dist/{types-C2RXaY0_.d.cts → types-CZTUCaE5.d.cts} +2 -0
  38. package/dist/{types-C2RXaY0_.d.ts → types-CZTUCaE5.d.ts} +2 -0
  39. package/dist/utils.cjs +9 -54
  40. package/dist/utils.cjs.map +1 -1
  41. package/dist/utils.d.cts +5 -35
  42. package/dist/utils.d.ts +5 -35
  43. package/dist/utils.js +2 -47
  44. package/dist/utils.js.map +1 -1
  45. package/package.json +9 -9
  46. package/src/SchemaGenerator.ts +2 -2
  47. package/src/SchemaMapper.ts +1 -1
  48. package/src/components/Schema.tsx +8 -4
  49. package/src/hooks/useOperationManager.ts +1 -0
  50. package/src/plugin.ts +11 -0
  51. package/src/types.ts +2 -0
  52. package/src/utils/index.ts +0 -1
  53. package/dist/chunk-7KIEQOVZ.cjs +0 -7
  54. package/dist/chunk-P42X362U.cjs.map +0 -1
  55. package/dist/chunk-RQZBFORW.cjs.map +0 -1
  56. package/src/utils/getGroupedByTagFiles.ts +0 -84
  57. /package/dist/{chunk-Y4V7HHX7.js.map → chunk-N7EEVJA6.js.map} +0 -0
  58. /package/dist/{chunk-TWKZEVSM.js.map → chunk-SQ64ESS4.js.map} +0 -0
@@ -1,13 +1,10 @@
1
1
  import {
2
2
  __commonJS,
3
- __privateAdd,
4
- __privateGet,
5
- __privateMethod,
6
3
  __toESM,
7
4
  getSchemaFactory,
8
5
  getSchemas,
9
6
  init_esm_shims
10
- } from "./chunk-UB552H4J.js";
7
+ } from "./chunk-SZDO532A.js";
11
8
 
12
9
  // ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
13
10
  var require_react_production_min = __commonJS({
@@ -3163,24 +3160,19 @@ import transformers, { pascalCase } from "@kubb/core/transformers";
3163
3160
  import { getUniqueName } from "@kubb/core/utils";
3164
3161
  import { isReference } from "@kubb/oas";
3165
3162
  import { isDeepEqual, isNumber, uniqueWith } from "remeda";
3166
- var _usedAliasNames, _SchemaGenerator_instances, getUsedEnumNames_fn, getOptions_fn, getUnknownReturn_fn, parseProperties_fn, getRefAlias_fn, getParsedSchemaObject_fn, parseSchemaObject_fn;
3167
- var _SchemaGenerator = class _SchemaGenerator extends Generator {
3168
- constructor() {
3169
- super(...arguments);
3170
- __privateAdd(this, _SchemaGenerator_instances);
3171
- // Collect the types of all referenced schemas, so we can export them later
3172
- this.refs = {};
3173
- // Keep track of already used type aliases
3174
- __privateAdd(this, _usedAliasNames, {});
3175
- }
3163
+ var SchemaGenerator = class _SchemaGenerator extends Generator {
3164
+ // Collect the types of all referenced schemas, so we can export them later
3165
+ refs = {};
3166
+ // Keep track of already used type aliases
3167
+ #usedAliasNames = {};
3176
3168
  /**
3177
3169
  * Creates a type node from a given schema.
3178
3170
  * Delegates to getBaseTypeFromSchema internally and
3179
3171
  * optionally adds a union with null.
3180
3172
  */
3181
3173
  parse(props) {
3182
- const options = __privateMethod(this, _SchemaGenerator_instances, getOptions_fn).call(this, props);
3183
- const defaultSchemas = __privateMethod(this, _SchemaGenerator_instances, parseSchemaObject_fn).call(this, props);
3174
+ const options = this.#getOptions(props);
3175
+ const defaultSchemas = this.#parseSchemaObject(props);
3184
3176
  const schemas = options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || [];
3185
3177
  return uniqueWith(schemas, isDeepEqual);
3186
3178
  }
@@ -3295,231 +3287,132 @@ var _SchemaGenerator = class _SchemaGenerator extends Generator {
3295
3287
  });
3296
3288
  return foundItem;
3297
3289
  }
3298
- async build(...parsers) {
3299
- const { oas, contentType, include } = this.context;
3300
- const schemas = getSchemas({ oas, contentType, includes: include });
3301
- const promises = Object.entries(schemas).reduce((acc, [name, schema]) => {
3302
- const options = __privateMethod(this, _SchemaGenerator_instances, getOptions_fn).call(this, { name });
3303
- const promiseOperation = this.schema.call(this, name, schema, {
3304
- ...this.options,
3305
- ...options
3306
- });
3307
- if (promiseOperation) {
3308
- acc.push(promiseOperation);
3309
- }
3310
- parsers?.forEach((parser) => {
3311
- const promise = parser.schema?.({
3312
- instance: this,
3313
- name,
3314
- schema,
3315
- options: {
3316
- ...this.options,
3317
- ...options
3318
- }
3319
- });
3320
- if (promise) {
3321
- acc.push(promise);
3290
+ #getUsedEnumNames(props) {
3291
+ const options = this.#getOptions(props);
3292
+ return options.usedEnumNames || {};
3293
+ }
3294
+ #getOptions({ name }) {
3295
+ const { override = [] } = this.context;
3296
+ return {
3297
+ ...this.options,
3298
+ ...override.find(({ pattern, type }) => {
3299
+ if (name && type === "schemaName") {
3300
+ return !!name.match(pattern);
3322
3301
  }
3323
- });
3324
- return acc;
3325
- }, []);
3326
- const files = await Promise.all(promises);
3327
- return files.flat().filter(Boolean);
3302
+ return false;
3303
+ })?.options || {}
3304
+ };
3305
+ }
3306
+ #getUnknownReturn(props) {
3307
+ const options = this.#getOptions(props);
3308
+ if (options.unknownType === "any") {
3309
+ return schemaKeywords.any;
3310
+ }
3311
+ return schemaKeywords.unknown;
3328
3312
  }
3329
3313
  /**
3330
- * Schema
3314
+ * Recursively creates a type literal with the given props.
3331
3315
  */
3332
- async schema(name, object, options) {
3333
- return [];
3334
- }
3335
- };
3336
- _usedAliasNames = new WeakMap();
3337
- _SchemaGenerator_instances = new WeakSet();
3338
- getUsedEnumNames_fn = function(props) {
3339
- const options = __privateMethod(this, _SchemaGenerator_instances, getOptions_fn).call(this, props);
3340
- return options.usedEnumNames || {};
3341
- };
3342
- getOptions_fn = function({ name }) {
3343
- const { override = [] } = this.context;
3344
- return {
3345
- ...this.options,
3346
- ...override.find(({ pattern, type }) => {
3347
- if (name && type === "schemaName") {
3348
- return !!name.match(pattern);
3316
+ #parseProperties({ schema, name }) {
3317
+ const properties = schema?.properties || {};
3318
+ const additionalProperties = schema?.additionalProperties;
3319
+ const required = schema?.required;
3320
+ const propertiesSchemas = Object.keys(properties).map((propertyName) => {
3321
+ const validationFunctions = [];
3322
+ const propertySchema = properties[propertyName];
3323
+ const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
3324
+ const nullable = propertySchema.nullable ?? propertySchema["x-nullable"] ?? false;
3325
+ validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }));
3326
+ validationFunctions.push({
3327
+ keyword: schemaKeywords.name,
3328
+ args: propertyName
3329
+ });
3330
+ if (!isRequired && nullable) {
3331
+ validationFunctions.push({ keyword: schemaKeywords.nullish });
3332
+ } else if (!isRequired) {
3333
+ validationFunctions.push({ keyword: schemaKeywords.optional });
3349
3334
  }
3350
- return false;
3351
- })?.options || {}
3352
- };
3353
- };
3354
- getUnknownReturn_fn = function(props) {
3355
- const options = __privateMethod(this, _SchemaGenerator_instances, getOptions_fn).call(this, props);
3356
- if (options.unknownType === "any") {
3357
- return schemaKeywords.any;
3335
+ return {
3336
+ [propertyName]: validationFunctions
3337
+ };
3338
+ }).reduce((acc, curr) => ({ ...acc, ...curr }), {});
3339
+ let additionalPropertiesSchemas = [];
3340
+ if (additionalProperties) {
3341
+ additionalPropertiesSchemas = additionalProperties === true ? [{ keyword: this.#getUnknownReturn({ schema, name }) }] : this.parse({ schema: additionalProperties, parentName: name });
3342
+ }
3343
+ return [
3344
+ {
3345
+ keyword: schemaKeywords.object,
3346
+ args: {
3347
+ properties: propertiesSchemas,
3348
+ additionalProperties: additionalPropertiesSchemas
3349
+ }
3350
+ }
3351
+ ];
3358
3352
  }
3359
- return schemaKeywords.unknown;
3360
- };
3361
- /**
3362
- * Recursively creates a type literal with the given props.
3363
- */
3364
- parseProperties_fn = function({ schema, name }) {
3365
- const properties = schema?.properties || {};
3366
- const additionalProperties = schema?.additionalProperties;
3367
- const required = schema?.required;
3368
- const propertiesSchemas = Object.keys(properties).map((propertyName) => {
3369
- const validationFunctions = [];
3370
- const propertySchema = properties[propertyName];
3371
- const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
3372
- const nullable = propertySchema.nullable ?? propertySchema["x-nullable"] ?? false;
3373
- validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }));
3374
- validationFunctions.push({
3375
- keyword: schemaKeywords.name,
3376
- args: propertyName
3353
+ /**
3354
+ * Create a type alias for the schema referenced by the given ReferenceObject
3355
+ */
3356
+ #getRefAlias(obj) {
3357
+ const { $ref } = obj;
3358
+ let ref = this.refs[$ref];
3359
+ const originalName = getUniqueName($ref.replace(/.+\//, ""), this.#usedAliasNames);
3360
+ const propertyName = this.context.pluginManager.resolveName({
3361
+ name: originalName,
3362
+ pluginKey: this.context.plugin.key,
3363
+ type: "function"
3377
3364
  });
3378
- if (!isRequired && nullable) {
3379
- validationFunctions.push({ keyword: schemaKeywords.nullish });
3380
- } else if (!isRequired) {
3381
- validationFunctions.push({ keyword: schemaKeywords.optional });
3365
+ if (ref) {
3366
+ return [
3367
+ {
3368
+ keyword: schemaKeywords.ref,
3369
+ args: { name: ref.propertyName, path: ref.path }
3370
+ }
3371
+ ];
3382
3372
  }
3383
- return {
3384
- [propertyName]: validationFunctions
3373
+ const fileName = this.context.pluginManager.resolveName({
3374
+ name: originalName,
3375
+ pluginKey: this.context.plugin.key,
3376
+ type: "file"
3377
+ });
3378
+ const file = this.context.pluginManager.getFile({
3379
+ name: fileName,
3380
+ pluginKey: this.context.plugin.key,
3381
+ extName: ".ts"
3382
+ });
3383
+ ref = this.refs[$ref] = {
3384
+ propertyName,
3385
+ originalName,
3386
+ path: file.path
3385
3387
  };
3386
- }).reduce((acc, curr) => ({ ...acc, ...curr }), {});
3387
- let additionalPropertiesSchemas = [];
3388
- if (additionalProperties) {
3389
- additionalPropertiesSchemas = additionalProperties === true ? [{ keyword: __privateMethod(this, _SchemaGenerator_instances, getUnknownReturn_fn).call(this, { schema, name }) }] : this.parse({ schema: additionalProperties, parentName: name });
3390
- }
3391
- return [
3392
- {
3393
- keyword: schemaKeywords.object,
3394
- args: {
3395
- properties: propertiesSchemas,
3396
- additionalProperties: additionalPropertiesSchemas
3397
- }
3398
- }
3399
- ];
3400
- };
3401
- /**
3402
- * Create a type alias for the schema referenced by the given ReferenceObject
3403
- */
3404
- getRefAlias_fn = function(obj) {
3405
- const { $ref } = obj;
3406
- let ref = this.refs[$ref];
3407
- const originalName = getUniqueName($ref.replace(/.+\//, ""), __privateGet(this, _usedAliasNames));
3408
- const propertyName = this.context.pluginManager.resolveName({
3409
- name: originalName,
3410
- pluginKey: this.context.plugin.key,
3411
- type: "function"
3412
- });
3413
- if (ref) {
3414
3388
  return [
3415
3389
  {
3416
3390
  keyword: schemaKeywords.ref,
3417
- args: { name: ref.propertyName, path: ref.path }
3391
+ args: { name: ref.propertyName, path: ref?.path }
3418
3392
  }
3419
3393
  ];
3420
3394
  }
3421
- const fileName = this.context.pluginManager.resolveName({
3422
- name: originalName,
3423
- pluginKey: this.context.plugin.key,
3424
- type: "file"
3425
- });
3426
- const file = this.context.pluginManager.getFile({
3427
- name: fileName,
3428
- pluginKey: this.context.plugin.key,
3429
- extName: ".ts"
3430
- });
3431
- ref = this.refs[$ref] = {
3432
- propertyName,
3433
- originalName,
3434
- path: file.path
3435
- };
3436
- return [
3437
- {
3438
- keyword: schemaKeywords.ref,
3439
- args: { name: ref.propertyName, path: ref?.path, isTypeOnly: false }
3440
- }
3441
- ];
3442
- };
3443
- getParsedSchemaObject_fn = function(schema) {
3444
- const parsedSchema = getSchemaFactory(this.context.oas)(schema);
3445
- return parsedSchema;
3446
- };
3447
- /**
3448
- * This is the very core of the OpenAPI to TS conversion - it takes a
3449
- * schema and returns the appropriate type.
3450
- */
3451
- parseSchemaObject_fn = function({ schema: _schema, name, parentName }) {
3452
- const options = __privateMethod(this, _SchemaGenerator_instances, getOptions_fn).call(this, { schema: _schema, name });
3453
- const unknownReturn = __privateMethod(this, _SchemaGenerator_instances, getUnknownReturn_fn).call(this, { schema: _schema, name });
3454
- const { schema, version } = __privateMethod(this, _SchemaGenerator_instances, getParsedSchemaObject_fn).call(this, _schema);
3455
- const resolvedName = this.context.pluginManager.resolveName({
3456
- name: `${parentName || ""} ${name}`,
3457
- pluginKey: this.context.plugin.key,
3458
- type: "type"
3459
- });
3460
- if (!schema) {
3461
- return [{ keyword: unknownReturn }];
3462
- }
3463
- const baseItems = [
3464
- {
3465
- keyword: schemaKeywords.schema,
3466
- args: {
3467
- type: schema.type,
3468
- format: schema.format
3469
- }
3470
- }
3471
- ];
3472
- const min = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
3473
- const max = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
3474
- const nullable = schema.nullable ?? schema["x-nullable"] ?? false;
3475
- if (schema.default !== void 0 && !Array.isArray(schema.default)) {
3476
- if (typeof schema.default === "string") {
3477
- baseItems.push({
3478
- keyword: schemaKeywords.default,
3479
- args: transformers.stringify(schema.default)
3480
- });
3481
- }
3482
- if (typeof schema.default === "boolean") {
3483
- baseItems.push({
3484
- keyword: schemaKeywords.default,
3485
- args: schema.default ?? false
3486
- });
3487
- }
3395
+ #getParsedSchemaObject(schema) {
3396
+ const parsedSchema = getSchemaFactory(this.context.oas)(schema);
3397
+ return parsedSchema;
3488
3398
  }
3489
- if (schema.description) {
3490
- baseItems.push({
3491
- keyword: schemaKeywords.describe,
3492
- args: schema.description
3493
- });
3494
- }
3495
- if (schema.pattern) {
3496
- baseItems.unshift({
3497
- keyword: schemaKeywords.matches,
3498
- args: schema.pattern
3399
+ /**
3400
+ * This is the very core of the OpenAPI to TS conversion - it takes a
3401
+ * schema and returns the appropriate type.
3402
+ */
3403
+ #parseSchemaObject({ schema: _schema, name, parentName }) {
3404
+ const options = this.#getOptions({ schema: _schema, name });
3405
+ const unknownReturn = this.#getUnknownReturn({ schema: _schema, name });
3406
+ const { schema, version } = this.#getParsedSchemaObject(_schema);
3407
+ const resolvedName = this.context.pluginManager.resolveName({
3408
+ name: `${parentName || ""} ${name}`,
3409
+ pluginKey: this.context.plugin.key,
3410
+ type: "type"
3499
3411
  });
3500
- }
3501
- if (max !== void 0) {
3502
- baseItems.unshift({ keyword: schemaKeywords.max, args: max });
3503
- }
3504
- if (min !== void 0) {
3505
- baseItems.unshift({ keyword: schemaKeywords.min, args: min });
3506
- }
3507
- if (nullable) {
3508
- baseItems.push({ keyword: schemaKeywords.nullable });
3509
- }
3510
- if (schema.type && Array.isArray(schema.type)) {
3511
- const [_schema2, nullable2] = schema.type;
3512
- if (nullable2 === "null") {
3513
- baseItems.push({ keyword: schemaKeywords.nullable });
3412
+ if (!schema) {
3413
+ return [{ keyword: unknownReturn }];
3514
3414
  }
3515
- }
3516
- if (schema.readOnly) {
3517
- baseItems.push({ keyword: schemaKeywords.readOnly });
3518
- }
3519
- if (isReference(schema)) {
3520
- return [
3521
- ...__privateMethod(this, _SchemaGenerator_instances, getRefAlias_fn).call(this, schema),
3522
- nullable && { keyword: schemaKeywords.nullable },
3415
+ const baseItems = [
3523
3416
  {
3524
3417
  keyword: schemaKeywords.schema,
3525
3418
  args: {
@@ -3527,285 +3420,381 @@ parseSchemaObject_fn = function({ schema: _schema, name, parentName }) {
3527
3420
  format: schema.format
3528
3421
  }
3529
3422
  }
3530
- ].filter(Boolean);
3531
- }
3532
- if (schema.oneOf) {
3533
- const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
3534
- const union = {
3535
- keyword: schemaKeywords.union,
3536
- args: schema.oneOf.map((item) => {
3537
- return item && this.parse({ schema: item, name, parentName })[0];
3538
- }).filter(Boolean).filter((item) => {
3539
- return item && item.keyword !== unknownReturn;
3540
- })
3541
- };
3542
- if (schemaWithoutOneOf.properties) {
3543
- return [...this.parse({ schema: schemaWithoutOneOf, name, parentName }), union, ...baseItems];
3423
+ ];
3424
+ const min = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
3425
+ const max = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
3426
+ const nullable = schema.nullable ?? schema["x-nullable"] ?? false;
3427
+ if (schema.default !== void 0 && !Array.isArray(schema.default)) {
3428
+ if (typeof schema.default === "string") {
3429
+ baseItems.push({
3430
+ keyword: schemaKeywords.default,
3431
+ args: transformers.stringify(schema.default)
3432
+ });
3433
+ }
3434
+ if (typeof schema.default === "boolean") {
3435
+ baseItems.push({
3436
+ keyword: schemaKeywords.default,
3437
+ args: schema.default ?? false
3438
+ });
3439
+ }
3544
3440
  }
3545
- return [union, ...baseItems];
3546
- }
3547
- if (schema.anyOf) {
3548
- const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
3549
- const union = {
3550
- keyword: schemaKeywords.union,
3551
- args: schema.anyOf.map((item) => {
3552
- return item && this.parse({ schema: item, name, parentName })[0];
3553
- }).filter(Boolean).filter((item) => {
3554
- return item && item.keyword !== unknownReturn;
3555
- }).map((item) => {
3556
- if (isKeyword(item, schemaKeywords.object)) {
3557
- return {
3558
- ...item,
3559
- args: {
3560
- ...item.args,
3561
- strict: true
3562
- }
3563
- };
3564
- }
3565
- return item;
3566
- })
3567
- };
3568
- if (schemaWithoutAnyOf.properties) {
3569
- return [...this.parse({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems];
3441
+ if (schema.description) {
3442
+ baseItems.push({
3443
+ keyword: schemaKeywords.describe,
3444
+ args: schema.description
3445
+ });
3570
3446
  }
3571
- return [union, ...baseItems];
3572
- }
3573
- if (schema.allOf) {
3574
- const schemaWithoutAllOf = { ...schema, allOf: void 0 };
3575
- const and = {
3576
- keyword: schemaKeywords.and,
3577
- args: schema.allOf.map((item) => {
3578
- return item && this.parse({ schema: item, name, parentName })[0];
3579
- }).filter(Boolean).filter((item) => {
3580
- return item && item.keyword !== unknownReturn;
3581
- })
3582
- };
3583
- if (schemaWithoutAllOf.properties) {
3584
- return [
3585
- {
3586
- ...and,
3587
- args: [...and.args || [], ...this.parse({ schema: schemaWithoutAllOf, name, parentName })]
3588
- },
3589
- ...baseItems
3590
- ];
3447
+ if (schema.pattern) {
3448
+ baseItems.unshift({
3449
+ keyword: schemaKeywords.matches,
3450
+ args: schema.pattern
3451
+ });
3591
3452
  }
3592
- return [and, ...baseItems];
3593
- }
3594
- if (schema.enum) {
3595
- const enumName = getUniqueName(pascalCase([parentName, name, options.enumSuffix].join(" ")), __privateMethod(this, _SchemaGenerator_instances, getUsedEnumNames_fn).call(this, { schema, name }));
3596
- const typeName = this.context.pluginManager.resolveName({
3597
- name: enumName,
3598
- pluginKey: this.context.plugin.key,
3599
- type: "type"
3600
- });
3601
- const nullableEnum = schema.enum.includes(null);
3602
- if (nullableEnum) {
3453
+ if (max !== void 0) {
3454
+ baseItems.unshift({ keyword: schemaKeywords.max, args: max });
3455
+ }
3456
+ if (min !== void 0) {
3457
+ baseItems.unshift({ keyword: schemaKeywords.min, args: min });
3458
+ }
3459
+ if (nullable) {
3603
3460
  baseItems.push({ keyword: schemaKeywords.nullable });
3604
3461
  }
3605
- const filteredValues = schema.enum.filter((value) => value !== null);
3606
- const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map((extensionKey) => {
3462
+ if (schema.type && Array.isArray(schema.type)) {
3463
+ const [_schema2, nullable2] = schema.type;
3464
+ if (nullable2 === "null") {
3465
+ baseItems.push({ keyword: schemaKeywords.nullable });
3466
+ }
3467
+ }
3468
+ if (schema.readOnly) {
3469
+ baseItems.push({ keyword: schemaKeywords.readOnly });
3470
+ }
3471
+ if (isReference(schema)) {
3607
3472
  return [
3473
+ ...this.#getRefAlias(schema),
3474
+ nullable && { keyword: schemaKeywords.nullable },
3608
3475
  {
3609
- keyword: schemaKeywords.enum,
3476
+ keyword: schemaKeywords.schema,
3610
3477
  args: {
3611
- name,
3612
- typeName,
3613
- asConst: false,
3614
- items: [...new Set(schema[extensionKey])].map((name2, index) => ({
3615
- name: transformers.stringify(name2),
3616
- value: schema.enum?.[index],
3617
- format: isNumber(schema.enum?.[index]) ? "number" : "string"
3618
- }))
3478
+ type: schema.type,
3479
+ format: schema.format
3619
3480
  }
3620
- },
3621
- ...baseItems.filter(
3622
- (item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches
3623
- )
3624
- ];
3625
- });
3626
- if (schema.type === "number" || schema.type === "integer") {
3627
- const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
3481
+ }
3482
+ ].filter(Boolean);
3483
+ }
3484
+ if (schema.oneOf) {
3485
+ const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
3486
+ const union = {
3487
+ keyword: schemaKeywords.union,
3488
+ args: schema.oneOf.map((item) => {
3489
+ return item && this.parse({ schema: item, name, parentName })[0];
3490
+ }).filter(Boolean).filter((item) => {
3491
+ return item && item.keyword !== unknownReturn;
3492
+ })
3493
+ };
3494
+ if (schemaWithoutOneOf.properties) {
3495
+ return [...this.parse({ schema: schemaWithoutOneOf, name, parentName }), union, ...baseItems];
3496
+ }
3497
+ return [union, ...baseItems];
3498
+ }
3499
+ if (schema.anyOf) {
3500
+ const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
3501
+ const union = {
3502
+ keyword: schemaKeywords.union,
3503
+ args: schema.anyOf.map((item) => {
3504
+ return item && this.parse({ schema: item, name, parentName })[0];
3505
+ }).filter(Boolean).filter((item) => {
3506
+ return item && item.keyword !== unknownReturn;
3507
+ }).map((item) => {
3508
+ if (isKeyword(item, schemaKeywords.object)) {
3509
+ return {
3510
+ ...item,
3511
+ args: {
3512
+ ...item.args,
3513
+ strict: true
3514
+ }
3515
+ };
3516
+ }
3517
+ return item;
3518
+ })
3519
+ };
3520
+ if (schemaWithoutAnyOf.properties) {
3521
+ return [...this.parse({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems];
3522
+ }
3523
+ return [union, ...baseItems];
3524
+ }
3525
+ if (schema.allOf) {
3526
+ const schemaWithoutAllOf = { ...schema, allOf: void 0 };
3527
+ const and = {
3528
+ keyword: schemaKeywords.and,
3529
+ args: schema.allOf.map((item) => {
3530
+ return item && this.parse({ schema: item, name, parentName })[0];
3531
+ }).filter(Boolean).filter((item) => {
3532
+ return item && item.keyword !== unknownReturn;
3533
+ })
3534
+ };
3535
+ if (schemaWithoutAllOf.properties) {
3536
+ return [
3537
+ {
3538
+ ...and,
3539
+ args: [...and.args || [], ...this.parse({ schema: schemaWithoutAllOf, name, parentName })]
3540
+ },
3541
+ ...baseItems
3542
+ ];
3543
+ }
3544
+ return [and, ...baseItems];
3545
+ }
3546
+ if (schema.enum) {
3547
+ const enumName = getUniqueName(pascalCase([parentName, name, options.enumSuffix].join(" ")), this.#getUsedEnumNames({ schema, name }));
3548
+ const typeName = this.context.pluginManager.resolveName({
3549
+ name: enumName,
3550
+ pluginKey: this.context.plugin.key,
3551
+ type: "type"
3552
+ });
3553
+ const nullableEnum = schema.enum.includes(null);
3554
+ if (nullableEnum) {
3555
+ baseItems.push({ keyword: schemaKeywords.nullable });
3556
+ }
3557
+ const filteredValues = schema.enum.filter((value) => value !== null);
3558
+ const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map((extensionKey) => {
3559
+ return [
3560
+ {
3561
+ keyword: schemaKeywords.enum,
3562
+ args: {
3563
+ name,
3564
+ typeName,
3565
+ asConst: false,
3566
+ items: [...new Set(schema[extensionKey])].map((name2, index) => ({
3567
+ name: transformers.stringify(name2),
3568
+ value: schema.enum?.[index],
3569
+ format: isNumber(schema.enum?.[index]) ? "number" : "string"
3570
+ }))
3571
+ }
3572
+ },
3573
+ ...baseItems.filter(
3574
+ (item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches
3575
+ )
3576
+ ];
3577
+ });
3578
+ if (schema.type === "number" || schema.type === "integer") {
3579
+ const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
3580
+ return [
3581
+ {
3582
+ keyword: schemaKeywords.enum,
3583
+ args: {
3584
+ name: enumName,
3585
+ typeName,
3586
+ asConst: true,
3587
+ items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
3588
+ name: name2,
3589
+ value,
3590
+ format: "number"
3591
+ })) : [...new Set(filteredValues)].map((value) => {
3592
+ return {
3593
+ name: value,
3594
+ value,
3595
+ format: "number"
3596
+ };
3597
+ })
3598
+ }
3599
+ },
3600
+ ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
3601
+ ];
3602
+ }
3603
+ if (extensionEnums.length > 0 && extensionEnums[0]) {
3604
+ return extensionEnums[0];
3605
+ }
3628
3606
  return [
3629
3607
  {
3630
3608
  keyword: schemaKeywords.enum,
3631
3609
  args: {
3632
3610
  name: enumName,
3633
3611
  typeName,
3634
- asConst: true,
3635
- items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
3636
- name: name2,
3612
+ asConst: false,
3613
+ items: [...new Set(filteredValues)].map((value) => ({
3614
+ name: transformers.stringify(value),
3637
3615
  value,
3638
- format: "number"
3639
- })) : [...new Set(filteredValues)].map((value) => {
3640
- return {
3641
- name: value,
3642
- value,
3643
- format: "number"
3644
- };
3645
- })
3616
+ format: isNumber(value) ? "number" : "string"
3617
+ }))
3646
3618
  }
3647
3619
  },
3648
3620
  ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
3649
3621
  ];
3650
3622
  }
3651
- if (extensionEnums.length > 0 && extensionEnums[0]) {
3652
- return extensionEnums[0];
3653
- }
3654
- return [
3655
- {
3656
- keyword: schemaKeywords.enum,
3657
- args: {
3658
- name: enumName,
3659
- typeName,
3660
- asConst: false,
3661
- items: [...new Set(filteredValues)].map((value) => ({
3662
- name: transformers.stringify(value),
3663
- value,
3664
- format: isNumber(value) ? "number" : "string"
3665
- }))
3666
- }
3667
- },
3668
- ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
3669
- ];
3670
- }
3671
- if ("prefixItems" in schema) {
3672
- const prefixItems = schema.prefixItems;
3673
- const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
3674
- const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
3675
- return [
3676
- {
3677
- keyword: schemaKeywords.tuple,
3678
- args: {
3679
- min: min2,
3680
- max: max2,
3681
- items: prefixItems.map((item) => {
3682
- return this.parse({ schema: item, name, parentName })[0];
3683
- }).filter(Boolean)
3684
- }
3685
- },
3686
- ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
3687
- ];
3688
- }
3689
- if (version === "3.1" && "const" in schema) {
3690
- if (schema["const"]) {
3623
+ if ("prefixItems" in schema) {
3624
+ const prefixItems = schema.prefixItems;
3625
+ const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
3626
+ const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
3691
3627
  return [
3692
3628
  {
3693
- keyword: schemaKeywords.const,
3629
+ keyword: schemaKeywords.tuple,
3694
3630
  args: {
3695
- name: schema["const"],
3696
- format: typeof schema["const"] === "number" ? "number" : "string",
3697
- value: schema["const"]
3631
+ min: min2,
3632
+ max: max2,
3633
+ items: prefixItems.map((item) => {
3634
+ return this.parse({ schema: item, name, parentName })[0];
3635
+ }).filter(Boolean)
3698
3636
  }
3699
3637
  },
3700
- ...baseItems
3638
+ ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
3701
3639
  ];
3702
3640
  }
3703
- return [{ keyword: schemaKeywords.null }];
3704
- }
3705
- if (schema.format) {
3706
- switch (schema.format) {
3707
- case "binary":
3708
- baseItems.push({ keyword: schemaKeywords.blob });
3709
- return baseItems;
3710
- case "date-time":
3711
- if (options.dateType) {
3712
- if (options.dateType === "date") {
3713
- baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
3714
- return baseItems;
3715
- }
3716
- if (options.dateType === "stringOffset") {
3717
- baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: true } });
3641
+ if (version === "3.1" && "const" in schema) {
3642
+ if (schema["const"]) {
3643
+ return [
3644
+ {
3645
+ keyword: schemaKeywords.const,
3646
+ args: {
3647
+ name: schema["const"],
3648
+ format: typeof schema["const"] === "number" ? "number" : "string",
3649
+ value: schema["const"]
3650
+ }
3651
+ },
3652
+ ...baseItems
3653
+ ];
3654
+ }
3655
+ return [{ keyword: schemaKeywords.null }];
3656
+ }
3657
+ if (schema.format) {
3658
+ switch (schema.format) {
3659
+ case "binary":
3660
+ baseItems.push({ keyword: schemaKeywords.blob });
3661
+ return baseItems;
3662
+ case "date-time":
3663
+ if (options.dateType) {
3664
+ if (options.dateType === "date") {
3665
+ baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
3666
+ return baseItems;
3667
+ }
3668
+ if (options.dateType === "stringOffset") {
3669
+ baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: true } });
3670
+ return baseItems;
3671
+ }
3672
+ if (options.dateType === "stringLocal") {
3673
+ baseItems.unshift({ keyword: schemaKeywords.datetime, args: { local: true } });
3674
+ return baseItems;
3675
+ }
3676
+ baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: false } });
3718
3677
  return baseItems;
3719
3678
  }
3720
- if (options.dateType === "stringLocal") {
3721
- baseItems.unshift({ keyword: schemaKeywords.datetime, args: { local: true } });
3679
+ break;
3680
+ case "date":
3681
+ if (options.dateType) {
3682
+ if (options.dateType === "date") {
3683
+ baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
3684
+ return baseItems;
3685
+ }
3686
+ baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "string" } });
3722
3687
  return baseItems;
3723
3688
  }
3724
- baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: false } });
3725
- return baseItems;
3726
- }
3727
- break;
3728
- case "date":
3729
- if (options.dateType) {
3730
- if (options.dateType === "date") {
3731
- baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
3689
+ break;
3690
+ case "time":
3691
+ if (options.dateType) {
3692
+ if (options.dateType === "date") {
3693
+ baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "date" } });
3694
+ return baseItems;
3695
+ }
3696
+ baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "string" } });
3732
3697
  return baseItems;
3733
3698
  }
3734
- baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "string" } });
3735
- return baseItems;
3736
- }
3737
- break;
3738
- case "time":
3739
- if (options.dateType) {
3740
- if (options.dateType === "date") {
3741
- baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "date" } });
3742
- return baseItems;
3699
+ break;
3700
+ case "uuid":
3701
+ baseItems.unshift({ keyword: schemaKeywords.uuid });
3702
+ break;
3703
+ case "email":
3704
+ case "idn-email":
3705
+ baseItems.unshift({ keyword: schemaKeywords.email });
3706
+ break;
3707
+ case "uri":
3708
+ case "ipv4":
3709
+ case "ipv6":
3710
+ case "uri-reference":
3711
+ case "hostname":
3712
+ case "idn-hostname":
3713
+ baseItems.unshift({ keyword: schemaKeywords.url });
3714
+ break;
3715
+ default:
3716
+ break;
3717
+ }
3718
+ }
3719
+ if ("items" in schema || schema.type === "array") {
3720
+ const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
3721
+ const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
3722
+ const items = this.parse({ schema: "items" in schema ? schema.items : [], name, parentName });
3723
+ return [
3724
+ {
3725
+ keyword: schemaKeywords.array,
3726
+ args: {
3727
+ items,
3728
+ min: min2,
3729
+ max: max2
3743
3730
  }
3744
- baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "string" } });
3745
- return baseItems;
3746
- }
3747
- break;
3748
- case "uuid":
3749
- baseItems.unshift({ keyword: schemaKeywords.uuid });
3750
- break;
3751
- case "email":
3752
- case "idn-email":
3753
- baseItems.unshift({ keyword: schemaKeywords.email });
3754
- break;
3755
- case "uri":
3756
- case "ipv4":
3757
- case "ipv6":
3758
- case "uri-reference":
3759
- case "hostname":
3760
- case "idn-hostname":
3761
- baseItems.unshift({ keyword: schemaKeywords.url });
3762
- break;
3763
- default:
3764
- break;
3731
+ },
3732
+ ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
3733
+ ];
3765
3734
  }
3735
+ if (schema.properties || schema.additionalProperties) {
3736
+ return [...this.#parseProperties({ schema, name }), ...baseItems];
3737
+ }
3738
+ if (schema.type) {
3739
+ if (Array.isArray(schema.type)) {
3740
+ const [type] = schema.type;
3741
+ return [
3742
+ ...this.parse({
3743
+ schema: {
3744
+ ...schema,
3745
+ type
3746
+ },
3747
+ name,
3748
+ parentName
3749
+ }),
3750
+ ...baseItems
3751
+ ].filter(Boolean);
3752
+ }
3753
+ if (!["boolean", "object", "number", "string", "integer"].includes(schema.type)) {
3754
+ this.context.pluginManager.logger.emit("warning", `Schema type '${schema.type}' is not valid for schema ${parentName}.${name}`);
3755
+ }
3756
+ return [{ keyword: schema.type }, ...baseItems];
3757
+ }
3758
+ return [{ keyword: unknownReturn }];
3766
3759
  }
3767
- if ("items" in schema || schema.type === "array") {
3768
- const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
3769
- const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
3770
- const items = this.parse({ schema: "items" in schema ? schema.items : [], name, parentName });
3771
- return [
3772
- {
3773
- keyword: schemaKeywords.array,
3774
- args: {
3775
- items,
3776
- min: min2,
3777
- max: max2
3760
+ async build(...parsers) {
3761
+ const { oas, contentType, include } = this.context;
3762
+ const schemas = getSchemas({ oas, contentType, includes: include });
3763
+ const promises = Object.entries(schemas).reduce((acc, [name, schema]) => {
3764
+ const options = this.#getOptions({ name });
3765
+ const promiseOperation = this.schema.call(this, name, schema, {
3766
+ ...this.options,
3767
+ ...options
3768
+ });
3769
+ if (promiseOperation) {
3770
+ acc.push(promiseOperation);
3771
+ }
3772
+ parsers?.forEach((parser) => {
3773
+ const promise = parser.schema?.({
3774
+ instance: this,
3775
+ name,
3776
+ schema,
3777
+ options: {
3778
+ ...this.options,
3779
+ ...options
3780
+ }
3781
+ });
3782
+ if (promise) {
3783
+ acc.push(promise);
3778
3784
  }
3779
- },
3780
- ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
3781
- ];
3782
- }
3783
- if (schema.properties || schema.additionalProperties) {
3784
- return [...__privateMethod(this, _SchemaGenerator_instances, parseProperties_fn).call(this, { schema, name }), ...baseItems];
3785
+ });
3786
+ return acc;
3787
+ }, []);
3788
+ const files = await Promise.all(promises);
3789
+ return files.flat().filter(Boolean);
3785
3790
  }
3786
- if (schema.type) {
3787
- if (Array.isArray(schema.type)) {
3788
- const [type] = schema.type;
3789
- return [
3790
- ...this.parse({
3791
- schema: {
3792
- ...schema,
3793
- type
3794
- },
3795
- name,
3796
- parentName
3797
- }),
3798
- ...baseItems
3799
- ].filter(Boolean);
3800
- }
3801
- if (!["boolean", "object", "number", "string", "integer"].includes(schema.type)) {
3802
- this.context.pluginManager.logger.emit("warning", `Schema type '${schema.type}' is not valid for schema ${parentName}.${name}`);
3803
- }
3804
- return [{ keyword: schema.type }, ...baseItems];
3791
+ /**
3792
+ * Schema
3793
+ */
3794
+ async schema(name, object, options) {
3795
+ return [];
3805
3796
  }
3806
- return [{ keyword: unknownReturn }];
3807
3797
  };
3808
- var SchemaGenerator = _SchemaGenerator;
3809
3798
 
3810
3799
  // src/components/Operation.tsx
3811
3800
  init_esm_shims();
@@ -3836,7 +3825,11 @@ Schema.File = function({ output, isTypeOnly, children }) {
3836
3825
  const { plugin, pluginManager, mode } = useApp();
3837
3826
  const { name } = useSchema();
3838
3827
  if (mode === "single") {
3839
- const baseName2 = output;
3828
+ const baseName2 = `${pluginManager.resolveName({
3829
+ name,
3830
+ pluginKey: plugin.key,
3831
+ type: "file"
3832
+ })}.ts`;
3840
3833
  const resolvedPath2 = pluginManager.resolvePath({
3841
3834
  baseName: "",
3842
3835
  pluginKey: plugin.key
@@ -3883,7 +3876,7 @@ Schema.File = function({ output, isTypeOnly, children }) {
3883
3876
  }
3884
3877
  );
3885
3878
  };
3886
- Schema.Imports = ({ isTypeOnly, extName }) => {
3879
+ Schema.Imports = ({ isTypeOnly }) => {
3887
3880
  const { tree } = useSchema();
3888
3881
  const { path: root } = useFile();
3889
3882
  const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref);
@@ -3891,7 +3884,7 @@ Schema.Imports = ({ isTypeOnly, extName }) => {
3891
3884
  if (!item.args.path) {
3892
3885
  return void 0;
3893
3886
  }
3894
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(File.Import, { root, name: [item.args.name], path: item.args.path, isTypeOnly: item.args.isTypeOnly ?? isTypeOnly }, i);
3887
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(File.Import, { root, name: [item.args.name], path: item.args.path, isTypeOnly }, i);
3895
3888
  }).filter(Boolean) });
3896
3889
  };
3897
3890
  Schema.Context = SchemaContext;
@@ -3970,4 +3963,4 @@ react/cjs/react-jsx-runtime.development.js:
3970
3963
  * LICENSE file in the root directory of this source tree.
3971
3964
  *)
3972
3965
  */
3973
- //# sourceMappingURL=chunk-UJNAXXVE.js.map
3966
+ //# sourceMappingURL=chunk-MUI5DWM3.js.map