@kubb/plugin-oas 3.0.0-alpha.2 → 3.0.0-alpha.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 (50) hide show
  1. package/dist/OperationGenerator-D7rSlflc.d.cts +158 -0
  2. package/dist/OperationGenerator-vw0Zf-Mi.d.ts +158 -0
  3. package/dist/{Schema-an5hOrjZ.d.cts → Schema-DxyOIX7q.d.cts} +1 -1
  4. package/dist/{Schema-DefwBJMc.d.ts → Schema-gHgN14i2.d.ts} +1 -1
  5. package/dist/{SchemaMapper-CsBQ6eEx.d.cts → SchemaMapper-BM1IGWqD.d.cts} +1 -1
  6. package/dist/{SchemaMapper-CsBQ6eEx.d.ts → SchemaMapper-BM1IGWqD.d.ts} +1 -1
  7. package/dist/{chunk-DRLYORTT.cjs → chunk-264TCCJF.cjs} +715 -7
  8. package/dist/chunk-264TCCJF.cjs.map +1 -0
  9. package/dist/chunk-7KIEQOVZ.cjs +7 -0
  10. package/dist/chunk-7KIEQOVZ.cjs.map +1 -0
  11. package/dist/{chunk-LEACSHKT.js → chunk-FZN3PBEK.js} +713 -5
  12. package/dist/chunk-FZN3PBEK.js.map +1 -0
  13. package/dist/chunk-TWKZEVSM.js +7 -0
  14. package/dist/chunk-TWKZEVSM.js.map +1 -0
  15. package/dist/components.cjs +4 -9
  16. package/dist/components.cjs.map +1 -1
  17. package/dist/components.d.cts +12 -6
  18. package/dist/components.d.ts +12 -6
  19. package/dist/components.js +3 -8
  20. package/dist/components.js.map +1 -1
  21. package/dist/hooks.cjs +6 -7
  22. package/dist/hooks.cjs.map +1 -1
  23. package/dist/hooks.d.cts +3 -3
  24. package/dist/hooks.d.ts +3 -3
  25. package/dist/hooks.js +1 -2
  26. package/dist/hooks.js.map +1 -1
  27. package/dist/index.cjs +225 -153
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +8 -77
  30. package/dist/index.d.ts +8 -77
  31. package/dist/index.js +207 -135
  32. package/dist/index.js.map +1 -1
  33. package/dist/{types-Dte3MA6H.d.cts → types-C2RXaY0_.d.cts} +1 -1
  34. package/dist/{types-Dte3MA6H.d.ts → types-C2RXaY0_.d.ts} +1 -1
  35. package/dist/utils.d.cts +2 -2
  36. package/dist/utils.d.ts +2 -2
  37. package/package.json +9 -9
  38. package/src/OperationGenerator.ts +62 -31
  39. package/src/SchemaGenerator.ts +23 -4
  40. package/src/components/Oas.tsx +8 -2
  41. package/src/index.ts +3 -9
  42. package/src/parser.tsx +120 -0
  43. package/dist/OperationGenerator-CeM_9pxW.d.cts +0 -60
  44. package/dist/OperationGenerator-DhUhvRJE.d.ts +0 -60
  45. package/dist/chunk-CJXRFYEF.cjs +0 -698
  46. package/dist/chunk-CJXRFYEF.cjs.map +0 -1
  47. package/dist/chunk-DRLYORTT.cjs.map +0 -1
  48. package/dist/chunk-K6KUETAI.js +0 -698
  49. package/dist/chunk-K6KUETAI.js.map +0 -1
  50. package/dist/chunk-LEACSHKT.js.map +0 -1
@@ -1,10 +1,11 @@
1
- import {
2
- SchemaGenerator,
3
- schemaKeywords
4
- } from "./chunk-K6KUETAI.js";
5
1
  import {
6
2
  __commonJS,
3
+ __privateAdd,
4
+ __privateGet,
5
+ __privateMethod,
7
6
  __toESM,
7
+ getSchemaFactory,
8
+ getSchemas,
8
9
  init_esm_shims
9
10
  } from "./chunk-UB552H4J.js";
10
11
 
@@ -3103,6 +3104,709 @@ var require_jsx_runtime = __commonJS({
3103
3104
  }
3104
3105
  });
3105
3106
 
3107
+ // src/SchemaMapper.ts
3108
+ init_esm_shims();
3109
+ var schemaKeywords = {
3110
+ any: "any",
3111
+ strict: "strict",
3112
+ unknown: "unknown",
3113
+ number: "number",
3114
+ integer: "integer",
3115
+ string: "string",
3116
+ boolean: "boolean",
3117
+ undefined: "undefined",
3118
+ nullable: "nullable",
3119
+ null: "null",
3120
+ nullish: "nullish",
3121
+ array: "array",
3122
+ tuple: "tuple",
3123
+ enum: "enum",
3124
+ union: "union",
3125
+ datetime: "datetime",
3126
+ date: "date",
3127
+ email: "email",
3128
+ uuid: "uuid",
3129
+ url: "url",
3130
+ /* intersection */
3131
+ default: "default",
3132
+ const: "const",
3133
+ and: "and",
3134
+ describe: "describe",
3135
+ min: "min",
3136
+ max: "max",
3137
+ optional: "optional",
3138
+ readOnly: "readOnly",
3139
+ // custom ones
3140
+ object: "object",
3141
+ ref: "ref",
3142
+ matches: "matches",
3143
+ firstName: "firstName",
3144
+ lastName: "lastName",
3145
+ password: "password",
3146
+ phone: "phone",
3147
+ blob: "blob",
3148
+ deprecated: "deprecated",
3149
+ example: "example",
3150
+ schema: "schema",
3151
+ catchall: "catchall",
3152
+ time: "time",
3153
+ name: "name"
3154
+ };
3155
+ function isKeyword(meta, keyword) {
3156
+ return meta.keyword === keyword;
3157
+ }
3158
+
3159
+ // src/SchemaGenerator.ts
3160
+ init_esm_shims();
3161
+ import { Generator } from "@kubb/core";
3162
+ import transformers, { pascalCase } from "@kubb/core/transformers";
3163
+ import { getUniqueName } from "@kubb/core/utils";
3164
+ import { isReference } from "@kubb/oas";
3165
+ 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
+ }
3176
+ /**
3177
+ * Creates a type node from a given schema.
3178
+ * Delegates to getBaseTypeFromSchema internally and
3179
+ * optionally adds a union with null.
3180
+ */
3181
+ 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);
3184
+ const schemas = options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || [];
3185
+ return uniqueWith(schemas, isDeepEqual);
3186
+ }
3187
+ deepSearch(tree, keyword) {
3188
+ return _SchemaGenerator.deepSearch(tree, keyword);
3189
+ }
3190
+ find(tree, keyword) {
3191
+ return _SchemaGenerator.find(tree, keyword);
3192
+ }
3193
+ static deepSearch(tree, keyword) {
3194
+ const foundItems = [];
3195
+ tree?.forEach((schema) => {
3196
+ if (schema.keyword === keyword) {
3197
+ foundItems.push(schema);
3198
+ }
3199
+ if (schema.keyword === schemaKeywords.object) {
3200
+ const subItem = schema;
3201
+ Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
3202
+ foundItems.push(..._SchemaGenerator.deepSearch(entrySchema, keyword));
3203
+ });
3204
+ Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
3205
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
3206
+ });
3207
+ }
3208
+ if (schema.keyword === schemaKeywords.array) {
3209
+ const subItem = schema;
3210
+ subItem.args.items.forEach((entrySchema) => {
3211
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
3212
+ });
3213
+ }
3214
+ if (schema.keyword === schemaKeywords.and) {
3215
+ const subItem = schema;
3216
+ subItem.args.forEach((entrySchema) => {
3217
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
3218
+ });
3219
+ }
3220
+ if (schema.keyword === schemaKeywords.tuple) {
3221
+ const subItem = schema;
3222
+ subItem.args.items.forEach((entrySchema) => {
3223
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
3224
+ });
3225
+ }
3226
+ if (schema.keyword === schemaKeywords.union) {
3227
+ const subItem = schema;
3228
+ subItem.args.forEach((entrySchema) => {
3229
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
3230
+ });
3231
+ }
3232
+ });
3233
+ return foundItems;
3234
+ }
3235
+ static findInObject(tree, keyword) {
3236
+ let foundItem = void 0;
3237
+ tree?.forEach((schema) => {
3238
+ if (!foundItem && schema.keyword === keyword) {
3239
+ foundItem = schema;
3240
+ }
3241
+ if (schema.keyword === schemaKeywords.object) {
3242
+ const subItem = schema;
3243
+ Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
3244
+ if (!foundItem) {
3245
+ foundItem = _SchemaGenerator.find(entrySchema, keyword);
3246
+ }
3247
+ });
3248
+ Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
3249
+ if (!foundItem) {
3250
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
3251
+ }
3252
+ });
3253
+ }
3254
+ });
3255
+ return foundItem;
3256
+ }
3257
+ static find(tree, keyword) {
3258
+ let foundItem = void 0;
3259
+ tree?.forEach((schema) => {
3260
+ if (!foundItem && schema.keyword === keyword) {
3261
+ foundItem = schema;
3262
+ }
3263
+ if (schema.keyword === schemaKeywords.array) {
3264
+ const subItem = schema;
3265
+ subItem.args.items.forEach((entrySchema) => {
3266
+ if (!foundItem) {
3267
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
3268
+ }
3269
+ });
3270
+ }
3271
+ if (schema.keyword === schemaKeywords.and) {
3272
+ const subItem = schema;
3273
+ subItem.args.forEach((entrySchema) => {
3274
+ if (!foundItem) {
3275
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
3276
+ }
3277
+ });
3278
+ }
3279
+ if (schema.keyword === schemaKeywords.tuple) {
3280
+ const subItem = schema;
3281
+ subItem.args.items.forEach((entrySchema) => {
3282
+ if (!foundItem) {
3283
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
3284
+ }
3285
+ });
3286
+ }
3287
+ if (schema.keyword === schemaKeywords.union) {
3288
+ const subItem = schema;
3289
+ subItem.args.forEach((entrySchema) => {
3290
+ if (!foundItem) {
3291
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
3292
+ }
3293
+ });
3294
+ }
3295
+ });
3296
+ return foundItem;
3297
+ }
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);
3322
+ }
3323
+ });
3324
+ return acc;
3325
+ }, []);
3326
+ const files = await Promise.all(promises);
3327
+ return files.flat().filter(Boolean);
3328
+ }
3329
+ /**
3330
+ * Schema
3331
+ */
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);
3349
+ }
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;
3358
+ }
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
3377
+ });
3378
+ if (!isRequired && nullable) {
3379
+ validationFunctions.push({ keyword: schemaKeywords.nullish });
3380
+ } else if (!isRequired) {
3381
+ validationFunctions.push({ keyword: schemaKeywords.optional });
3382
+ }
3383
+ return {
3384
+ [propertyName]: validationFunctions
3385
+ };
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
+ return [
3415
+ {
3416
+ keyword: schemaKeywords.ref,
3417
+ args: { name: ref.propertyName, path: ref.path }
3418
+ }
3419
+ ];
3420
+ }
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
+ }
3488
+ }
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
3499
+ });
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 });
3514
+ }
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 },
3523
+ {
3524
+ keyword: schemaKeywords.schema,
3525
+ args: {
3526
+ type: schema.type,
3527
+ format: schema.format
3528
+ }
3529
+ }
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];
3544
+ }
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];
3570
+ }
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
+ ];
3591
+ }
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) {
3603
+ baseItems.push({ keyword: schemaKeywords.nullable });
3604
+ }
3605
+ const filteredValues = schema.enum.filter((value) => value !== null);
3606
+ const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map((extensionKey) => {
3607
+ return [
3608
+ {
3609
+ keyword: schemaKeywords.enum,
3610
+ 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
+ }))
3619
+ }
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));
3628
+ return [
3629
+ {
3630
+ keyword: schemaKeywords.enum,
3631
+ args: {
3632
+ name: enumName,
3633
+ typeName,
3634
+ asConst: true,
3635
+ items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
3636
+ name: name2,
3637
+ value,
3638
+ format: "number"
3639
+ })) : [...new Set(filteredValues)].map((value) => {
3640
+ return {
3641
+ name: value,
3642
+ value,
3643
+ format: "number"
3644
+ };
3645
+ })
3646
+ }
3647
+ },
3648
+ ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
3649
+ ];
3650
+ }
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"]) {
3691
+ return [
3692
+ {
3693
+ keyword: schemaKeywords.const,
3694
+ args: {
3695
+ name: schema["const"],
3696
+ format: typeof schema["const"] === "number" ? "number" : "string",
3697
+ value: schema["const"]
3698
+ }
3699
+ },
3700
+ ...baseItems
3701
+ ];
3702
+ }
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 } });
3718
+ return baseItems;
3719
+ }
3720
+ if (options.dateType === "stringLocal") {
3721
+ baseItems.unshift({ keyword: schemaKeywords.datetime, args: { local: true } });
3722
+ return baseItems;
3723
+ }
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" } });
3732
+ return baseItems;
3733
+ }
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;
3743
+ }
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;
3765
+ }
3766
+ }
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
3778
+ }
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
+ 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];
3805
+ }
3806
+ return [{ keyword: unknownReturn }];
3807
+ };
3808
+ var SchemaGenerator = _SchemaGenerator;
3809
+
3106
3810
  // src/components/Operation.tsx
3107
3811
  init_esm_shims();
3108
3812
  var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
@@ -3211,6 +3915,10 @@ Oas.Operation = Operation;
3211
3915
  Oas.Schema = Schema;
3212
3916
 
3213
3917
  export {
3918
+ schemaKeywords,
3919
+ isKeyword,
3920
+ SchemaGenerator,
3921
+ require_jsx_runtime,
3214
3922
  Operation,
3215
3923
  useSchema,
3216
3924
  Schema,
@@ -3262,4 +3970,4 @@ react/cjs/react-jsx-runtime.development.js:
3262
3970
  * LICENSE file in the root directory of this source tree.
3263
3971
  *)
3264
3972
  */
3265
- //# sourceMappingURL=chunk-LEACSHKT.js.map
3973
+ //# sourceMappingURL=chunk-FZN3PBEK.js.map