@kubb/plugin-oas 2.18.4 → 2.18.6

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 (68) hide show
  1. package/dist/{OperationGenerator-X6CTMfhG.d.cts → OperationGenerator-B6_KXF47.d.cts} +12 -11
  2. package/dist/{OperationGenerator-DvnXUUp4.d.ts → OperationGenerator-BL3W1CH2.d.ts} +12 -11
  3. package/dist/{Schema-DFZBfjF2.d.ts → Schema-ByMOp8RL.d.ts} +6 -12
  4. package/dist/{Schema-BWPWyiQO.d.cts → Schema-C9Wxng-Q.d.cts} +6 -12
  5. package/dist/{SchemaGenerator-hK5SHxTI.d.ts → SchemaMapper-DRlWYDvv.d.cts} +2 -74
  6. package/dist/{SchemaGenerator-z_7YrAAB.d.cts → SchemaMapper-DRlWYDvv.d.ts} +2 -74
  7. package/dist/{chunk-UMYKVV7G.js → chunk-37DRAF2Z.js} +49 -2
  8. package/dist/chunk-37DRAF2Z.js.map +1 -0
  9. package/dist/chunk-CTFUZW3D.cjs +682 -0
  10. package/dist/chunk-CTFUZW3D.cjs.map +1 -0
  11. package/dist/{chunk-XML4KQ5H.js → chunk-FL37EDQ2.js} +12 -30
  12. package/dist/{chunk-XML4KQ5H.js.map → chunk-FL37EDQ2.js.map} +1 -1
  13. package/dist/chunk-JWIFGIVZ.js +34 -0
  14. package/dist/chunk-JWIFGIVZ.js.map +1 -0
  15. package/dist/{chunk-YI3FIAD4.cjs → chunk-OUN5NRHC.cjs} +30 -48
  16. package/dist/chunk-OUN5NRHC.cjs.map +1 -0
  17. package/dist/chunk-QLNCBDLM.js +682 -0
  18. package/dist/chunk-QLNCBDLM.js.map +1 -0
  19. package/dist/chunk-R4EI2NRQ.cjs +34 -0
  20. package/dist/chunk-R4EI2NRQ.cjs.map +1 -0
  21. package/dist/{chunk-BDNSPC5Z.cjs → chunk-SSSTH6CP.cjs} +50 -3
  22. package/dist/chunk-SSSTH6CP.cjs.map +1 -0
  23. package/dist/components.cjs +5 -5
  24. package/dist/components.d.cts +5 -4
  25. package/dist/components.d.ts +5 -4
  26. package/dist/components.js +3 -3
  27. package/dist/hooks.cjs +13 -13
  28. package/dist/hooks.cjs.map +1 -1
  29. package/dist/hooks.d.cts +7 -8
  30. package/dist/hooks.d.ts +7 -8
  31. package/dist/hooks.js +3 -3
  32. package/dist/hooks.js.map +1 -1
  33. package/dist/index.cjs +69 -642
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +72 -6
  36. package/dist/index.d.ts +72 -6
  37. package/dist/index.js +50 -623
  38. package/dist/index.js.map +1 -1
  39. package/dist/{types-n5zV4Q3s.d.cts → types-BMBTfHxe.d.cts} +3 -2
  40. package/dist/{types-n5zV4Q3s.d.ts → types-BMBTfHxe.d.ts} +3 -2
  41. package/dist/utils.cjs +9 -9
  42. package/dist/utils.cjs.map +1 -1
  43. package/dist/utils.d.cts +5 -4
  44. package/dist/utils.d.ts +5 -4
  45. package/dist/utils.js +5 -5
  46. package/dist/utils.js.map +1 -1
  47. package/package.json +10 -9
  48. package/src/OperationGenerator.ts +27 -11
  49. package/src/SchemaGenerator.ts +30 -35
  50. package/src/SchemaMapper.ts +1 -1
  51. package/src/components/Schema.tsx +12 -42
  52. package/src/hooks/useOperationManager.ts +3 -2
  53. package/src/hooks/useSchema.ts +1 -8
  54. package/src/index.ts +1 -0
  55. package/src/plugin.ts +3 -3
  56. package/src/types.ts +3 -1
  57. package/src/utils/getGroupedByTagFiles.ts +4 -3
  58. package/dist/chunk-4OLWDMEK.cjs +0 -61
  59. package/dist/chunk-4OLWDMEK.cjs.map +0 -1
  60. package/dist/chunk-BDNSPC5Z.cjs.map +0 -1
  61. package/dist/chunk-BIJSTJCQ.js +0 -61
  62. package/dist/chunk-BIJSTJCQ.js.map +0 -1
  63. package/dist/chunk-I2JOGJIB.cjs +0 -81
  64. package/dist/chunk-I2JOGJIB.cjs.map +0 -1
  65. package/dist/chunk-UMYKVV7G.js.map +0 -1
  66. package/dist/chunk-XRPYJNPR.js +0 -81
  67. package/dist/chunk-XRPYJNPR.js.map +0 -1
  68. package/dist/chunk-YI3FIAD4.cjs.map +0 -1
@@ -0,0 +1,682 @@
1
+ import {
2
+ __privateAdd,
3
+ __privateGet,
4
+ __privateMethod,
5
+ getSchemaFactory,
6
+ getSchemas,
7
+ init_esm_shims
8
+ } from "./chunk-37DRAF2Z.js";
9
+
10
+ // src/SchemaMapper.ts
11
+ init_esm_shims();
12
+ var schemaKeywords = {
13
+ any: "any",
14
+ strict: "strict",
15
+ unknown: "unknown",
16
+ number: "number",
17
+ integer: "integer",
18
+ string: "string",
19
+ boolean: "boolean",
20
+ undefined: "undefined",
21
+ nullable: "nullable",
22
+ null: "null",
23
+ nullish: "nullish",
24
+ array: "array",
25
+ tuple: "tuple",
26
+ enum: "enum",
27
+ union: "union",
28
+ datetime: "datetime",
29
+ date: "date",
30
+ email: "email",
31
+ uuid: "uuid",
32
+ url: "url",
33
+ /* intersection */
34
+ default: "default",
35
+ const: "const",
36
+ and: "and",
37
+ describe: "describe",
38
+ min: "min",
39
+ max: "max",
40
+ optional: "optional",
41
+ readOnly: "readOnly",
42
+ // custom ones
43
+ object: "object",
44
+ ref: "ref",
45
+ matches: "matches",
46
+ firstName: "firstName",
47
+ lastName: "lastName",
48
+ password: "password",
49
+ phone: "phone",
50
+ blob: "blob",
51
+ deprecated: "deprecated",
52
+ example: "example",
53
+ schema: "schema",
54
+ catchall: "catchall",
55
+ time: "time",
56
+ name: "name"
57
+ };
58
+ function isKeyword(meta, keyword) {
59
+ return meta.keyword === keyword;
60
+ }
61
+
62
+ // src/SchemaGenerator.ts
63
+ init_esm_shims();
64
+ import { Generator } from "@kubb/core";
65
+ import transformers, { pascalCase } from "@kubb/core/transformers";
66
+ import { getUniqueName } from "@kubb/core/utils";
67
+ import { isReference } from "@kubb/oas";
68
+ import { isDeepEqual, isNumber, uniqueWith } from "remeda";
69
+ var _usedAliasNames, _getUsedEnumNames, getUsedEnumNames_fn, _getOptions, getOptions_fn, _getUnknownReturn, getUnknownReturn_fn, _parseProperties, parseProperties_fn, _getRefAlias, getRefAlias_fn, _getParsedSchemaObject, getParsedSchemaObject_fn, _parseSchemaObject, parseSchemaObject_fn;
70
+ var _SchemaGenerator = class _SchemaGenerator extends Generator {
71
+ constructor() {
72
+ super(...arguments);
73
+ __privateAdd(this, _getUsedEnumNames);
74
+ __privateAdd(this, _getOptions);
75
+ __privateAdd(this, _getUnknownReturn);
76
+ /**
77
+ * Recursively creates a type literal with the given props.
78
+ */
79
+ __privateAdd(this, _parseProperties);
80
+ /**
81
+ * Create a type alias for the schema referenced by the given ReferenceObject
82
+ */
83
+ __privateAdd(this, _getRefAlias);
84
+ __privateAdd(this, _getParsedSchemaObject);
85
+ /**
86
+ * This is the very core of the OpenAPI to TS conversion - it takes a
87
+ * schema and returns the appropriate type.
88
+ */
89
+ __privateAdd(this, _parseSchemaObject);
90
+ // Collect the types of all referenced schemas, so we can export them later
91
+ this.refs = {};
92
+ // Keep track of already used type aliases
93
+ __privateAdd(this, _usedAliasNames, {});
94
+ }
95
+ /**
96
+ * Creates a type node from a given schema.
97
+ * Delegates to getBaseTypeFromSchema internally and
98
+ * optionally adds a union with null.
99
+ */
100
+ parse(props) {
101
+ const options = __privateMethod(this, _getOptions, getOptions_fn).call(this, props);
102
+ const defaultSchemas = __privateMethod(this, _parseSchemaObject, parseSchemaObject_fn).call(this, props);
103
+ const schemas = options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || [];
104
+ return uniqueWith(schemas, isDeepEqual);
105
+ }
106
+ deepSearch(tree, keyword) {
107
+ return _SchemaGenerator.deepSearch(tree, keyword);
108
+ }
109
+ find(tree, keyword) {
110
+ return _SchemaGenerator.find(tree, keyword);
111
+ }
112
+ static deepSearch(tree, keyword) {
113
+ const foundItems = [];
114
+ tree?.forEach((schema) => {
115
+ if (schema.keyword === keyword) {
116
+ foundItems.push(schema);
117
+ }
118
+ if (schema.keyword === schemaKeywords.object) {
119
+ const subItem = schema;
120
+ Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
121
+ foundItems.push(..._SchemaGenerator.deepSearch(entrySchema, keyword));
122
+ });
123
+ Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
124
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
125
+ });
126
+ }
127
+ if (schema.keyword === schemaKeywords.array) {
128
+ const subItem = schema;
129
+ subItem.args.items.forEach((entrySchema) => {
130
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
131
+ });
132
+ }
133
+ if (schema.keyword === schemaKeywords.and) {
134
+ const subItem = schema;
135
+ subItem.args.forEach((entrySchema) => {
136
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
137
+ });
138
+ }
139
+ if (schema.keyword === schemaKeywords.tuple) {
140
+ const subItem = schema;
141
+ subItem.args.forEach((entrySchema) => {
142
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
143
+ });
144
+ }
145
+ if (schema.keyword === schemaKeywords.union) {
146
+ const subItem = schema;
147
+ subItem.args.forEach((entrySchema) => {
148
+ foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
149
+ });
150
+ }
151
+ });
152
+ return foundItems;
153
+ }
154
+ static findInObject(tree, keyword) {
155
+ let foundItem = void 0;
156
+ tree?.forEach((schema) => {
157
+ if (!foundItem && schema.keyword === keyword) {
158
+ foundItem = schema;
159
+ }
160
+ if (schema.keyword === schemaKeywords.object) {
161
+ const subItem = schema;
162
+ Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
163
+ if (!foundItem) {
164
+ foundItem = _SchemaGenerator.find(entrySchema, keyword);
165
+ }
166
+ });
167
+ Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
168
+ if (!foundItem) {
169
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
170
+ }
171
+ });
172
+ }
173
+ });
174
+ return foundItem;
175
+ }
176
+ static find(tree, keyword) {
177
+ let foundItem = void 0;
178
+ tree?.forEach((schema) => {
179
+ if (!foundItem && schema.keyword === keyword) {
180
+ foundItem = schema;
181
+ }
182
+ if (schema.keyword === schemaKeywords.array) {
183
+ const subItem = schema;
184
+ subItem.args.items.forEach((entrySchema) => {
185
+ if (!foundItem) {
186
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
187
+ }
188
+ });
189
+ }
190
+ if (schema.keyword === schemaKeywords.and) {
191
+ const subItem = schema;
192
+ subItem.args.forEach((entrySchema) => {
193
+ if (!foundItem) {
194
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
195
+ }
196
+ });
197
+ }
198
+ if (schema.keyword === schemaKeywords.tuple) {
199
+ const subItem = schema;
200
+ subItem.args.forEach((entrySchema) => {
201
+ if (!foundItem) {
202
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
203
+ }
204
+ });
205
+ }
206
+ if (schema.keyword === schemaKeywords.union) {
207
+ const subItem = schema;
208
+ subItem.args.forEach((entrySchema) => {
209
+ if (!foundItem) {
210
+ foundItem = _SchemaGenerator.find([entrySchema], keyword);
211
+ }
212
+ });
213
+ }
214
+ });
215
+ return foundItem;
216
+ }
217
+ async build() {
218
+ const { oas, contentType, include } = this.context;
219
+ const schemas = getSchemas({ oas, contentType, includes: include });
220
+ const promises = Object.entries(schemas).reduce((acc, [name, schema]) => {
221
+ const promiseOperation = this.schema.call(this, name, schema);
222
+ if (promiseOperation) {
223
+ acc.push(promiseOperation);
224
+ }
225
+ return acc;
226
+ }, []);
227
+ const files = await Promise.all(promises);
228
+ return files.flat().filter(Boolean);
229
+ }
230
+ };
231
+ _usedAliasNames = new WeakMap();
232
+ _getUsedEnumNames = new WeakSet();
233
+ getUsedEnumNames_fn = function(props) {
234
+ const options = __privateMethod(this, _getOptions, getOptions_fn).call(this, props);
235
+ return options.usedEnumNames || {};
236
+ };
237
+ _getOptions = new WeakSet();
238
+ getOptions_fn = function({ name }) {
239
+ const { override = [] } = this.context;
240
+ return {
241
+ ...this.options,
242
+ ...override.find(({ pattern, type }) => {
243
+ if (name && type === "schemaName") {
244
+ return !!name.match(pattern);
245
+ }
246
+ return false;
247
+ })?.options || {}
248
+ };
249
+ };
250
+ _getUnknownReturn = new WeakSet();
251
+ getUnknownReturn_fn = function(props) {
252
+ const options = __privateMethod(this, _getOptions, getOptions_fn).call(this, props);
253
+ if (options.unknownType === "any") {
254
+ return schemaKeywords.any;
255
+ }
256
+ return schemaKeywords.unknown;
257
+ };
258
+ _parseProperties = new WeakSet();
259
+ parseProperties_fn = function({ schema, name }) {
260
+ const properties = schema?.properties || {};
261
+ const additionalProperties = schema?.additionalProperties;
262
+ const required = schema?.required;
263
+ const propertiesSchemas = Object.keys(properties).map((propertyName) => {
264
+ const validationFunctions = [];
265
+ const propertySchema = properties[propertyName];
266
+ const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
267
+ const nullable = propertySchema.nullable ?? propertySchema["x-nullable"] ?? false;
268
+ validationFunctions.push(...this.parse({ schema: propertySchema, name: propertyName, parentName: name }));
269
+ validationFunctions.push({
270
+ keyword: schemaKeywords.name,
271
+ args: propertyName
272
+ });
273
+ if (!isRequired && nullable) {
274
+ validationFunctions.push({ keyword: schemaKeywords.nullish });
275
+ } else if (!isRequired) {
276
+ validationFunctions.push({ keyword: schemaKeywords.optional });
277
+ }
278
+ return {
279
+ [propertyName]: validationFunctions
280
+ };
281
+ }).reduce((acc, curr) => ({ ...acc, ...curr }), {});
282
+ let additionalPropertiesSchemas = [];
283
+ if (additionalProperties) {
284
+ additionalPropertiesSchemas = additionalProperties === true ? [{ keyword: __privateMethod(this, _getUnknownReturn, getUnknownReturn_fn).call(this, { schema, name }) }] : this.parse({ schema: additionalProperties, parentName: name });
285
+ }
286
+ return [
287
+ {
288
+ keyword: schemaKeywords.object,
289
+ args: {
290
+ properties: propertiesSchemas,
291
+ additionalProperties: additionalPropertiesSchemas
292
+ }
293
+ }
294
+ ];
295
+ };
296
+ _getRefAlias = new WeakSet();
297
+ getRefAlias_fn = function(obj) {
298
+ const { $ref } = obj;
299
+ let ref = this.refs[$ref];
300
+ const originalName = getUniqueName($ref.replace(/.+\//, ""), __privateGet(this, _usedAliasNames));
301
+ const propertyName = this.context.pluginManager.resolveName({
302
+ name: originalName,
303
+ pluginKey: this.context.plugin.key,
304
+ type: "function"
305
+ });
306
+ if (ref) {
307
+ return [
308
+ {
309
+ keyword: schemaKeywords.ref,
310
+ args: { name: ref.propertyName, path: ref.path }
311
+ }
312
+ ];
313
+ }
314
+ const fileName = this.context.pluginManager.resolveName({
315
+ name: originalName,
316
+ pluginKey: this.context.plugin.key,
317
+ type: "file"
318
+ });
319
+ const file = this.context.pluginManager.getFile({
320
+ name: fileName,
321
+ pluginKey: this.context.plugin.key,
322
+ extName: ".ts"
323
+ });
324
+ ref = this.refs[$ref] = {
325
+ propertyName,
326
+ originalName,
327
+ path: file.path
328
+ };
329
+ return [
330
+ {
331
+ keyword: schemaKeywords.ref,
332
+ args: { name: ref.propertyName, path: ref?.path, isTypeOnly: false }
333
+ }
334
+ ];
335
+ };
336
+ _getParsedSchemaObject = new WeakSet();
337
+ getParsedSchemaObject_fn = function(schema) {
338
+ const parsedSchema = getSchemaFactory(this.context.oas)(schema);
339
+ return parsedSchema;
340
+ };
341
+ _parseSchemaObject = new WeakSet();
342
+ parseSchemaObject_fn = function({ schema: _schema, name, parentName }) {
343
+ const options = __privateMethod(this, _getOptions, getOptions_fn).call(this, { schema: _schema, name });
344
+ const unknownReturn = __privateMethod(this, _getUnknownReturn, getUnknownReturn_fn).call(this, { schema: _schema, name });
345
+ const { schema, version } = __privateMethod(this, _getParsedSchemaObject, getParsedSchemaObject_fn).call(this, _schema);
346
+ const resolvedName = this.context.pluginManager.resolveName({
347
+ name: `${parentName || ""} ${name}`,
348
+ pluginKey: this.context.plugin.key,
349
+ type: "type"
350
+ });
351
+ if (!schema) {
352
+ return [{ keyword: unknownReturn }];
353
+ }
354
+ const baseItems = [
355
+ {
356
+ keyword: schemaKeywords.schema,
357
+ args: {
358
+ type: schema.type,
359
+ format: schema.format
360
+ }
361
+ }
362
+ ];
363
+ const min = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
364
+ const max = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
365
+ const nullable = schema.nullable ?? schema["x-nullable"] ?? false;
366
+ if (schema.default !== void 0 && !Array.isArray(schema.default)) {
367
+ if (typeof schema.default === "string") {
368
+ baseItems.push({
369
+ keyword: schemaKeywords.default,
370
+ args: transformers.stringify(schema.default)
371
+ });
372
+ }
373
+ if (typeof schema.default === "boolean") {
374
+ baseItems.push({
375
+ keyword: schemaKeywords.default,
376
+ args: schema.default ?? false
377
+ });
378
+ }
379
+ }
380
+ if (schema.description) {
381
+ baseItems.push({
382
+ keyword: schemaKeywords.describe,
383
+ args: schema.description
384
+ });
385
+ }
386
+ if (schema.pattern) {
387
+ baseItems.unshift({
388
+ keyword: schemaKeywords.matches,
389
+ args: schema.pattern
390
+ });
391
+ }
392
+ if (max !== void 0) {
393
+ baseItems.unshift({ keyword: schemaKeywords.max, args: max });
394
+ }
395
+ if (min !== void 0) {
396
+ baseItems.unshift({ keyword: schemaKeywords.min, args: min });
397
+ }
398
+ if (nullable) {
399
+ baseItems.push({ keyword: schemaKeywords.nullable });
400
+ }
401
+ if (schema.type && Array.isArray(schema.type)) {
402
+ const [_schema2, nullable2] = schema.type;
403
+ if (nullable2 === "null") {
404
+ baseItems.push({ keyword: schemaKeywords.nullable });
405
+ }
406
+ }
407
+ if (schema.readOnly) {
408
+ baseItems.push({ keyword: schemaKeywords.readOnly });
409
+ }
410
+ if (isReference(schema)) {
411
+ return [...__privateMethod(this, _getRefAlias, getRefAlias_fn).call(this, schema), ...baseItems];
412
+ }
413
+ if (schema.oneOf) {
414
+ const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
415
+ const union = {
416
+ keyword: schemaKeywords.union,
417
+ args: schema.oneOf.map((item) => {
418
+ return item && this.parse({ schema: item, name, parentName })[0];
419
+ }).filter(Boolean).filter((item) => {
420
+ return item && item.keyword !== unknownReturn;
421
+ })
422
+ };
423
+ if (schemaWithoutOneOf.properties) {
424
+ return [...this.parse({ schema: schemaWithoutOneOf, name, parentName }), union, ...baseItems];
425
+ }
426
+ return [union, ...baseItems];
427
+ }
428
+ if (schema.anyOf) {
429
+ const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
430
+ const union = {
431
+ keyword: schemaKeywords.union,
432
+ args: schema.anyOf.map((item) => {
433
+ return item && this.parse({ schema: item, name, parentName })[0];
434
+ }).filter(Boolean).filter((item) => {
435
+ return item && item.keyword !== unknownReturn;
436
+ }).map((item) => {
437
+ if (isKeyword(item, schemaKeywords.object)) {
438
+ return {
439
+ ...item,
440
+ args: {
441
+ ...item.args,
442
+ strict: true
443
+ }
444
+ };
445
+ }
446
+ return item;
447
+ })
448
+ };
449
+ if (schemaWithoutAnyOf.properties) {
450
+ return [...this.parse({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems];
451
+ }
452
+ return [union, ...baseItems];
453
+ }
454
+ if (schema.allOf) {
455
+ const schemaWithoutAllOf = { ...schema, allOf: void 0 };
456
+ const and = {
457
+ keyword: schemaKeywords.and,
458
+ args: schema.allOf.map((item) => {
459
+ return item && this.parse({ schema: item, name, parentName })[0];
460
+ }).filter(Boolean).filter((item) => {
461
+ return item && item.keyword !== unknownReturn;
462
+ })
463
+ };
464
+ if (schemaWithoutAllOf.properties) {
465
+ return [
466
+ {
467
+ ...and,
468
+ args: [...and.args || [], ...this.parse({ schema: schemaWithoutAllOf, name, parentName })]
469
+ },
470
+ ...baseItems
471
+ ];
472
+ }
473
+ return [and, ...baseItems];
474
+ }
475
+ if (schema.enum) {
476
+ const enumName = getUniqueName(pascalCase([parentName, name, options.enumSuffix].join(" ")), __privateMethod(this, _getUsedEnumNames, getUsedEnumNames_fn).call(this, { schema, name }));
477
+ const typeName = this.context.pluginManager.resolveName({
478
+ name: enumName,
479
+ pluginKey: this.context.plugin.key,
480
+ type: "type"
481
+ });
482
+ const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map((extensionKey) => {
483
+ return [
484
+ {
485
+ keyword: schemaKeywords.enum,
486
+ args: {
487
+ name,
488
+ typeName,
489
+ asConst: false,
490
+ items: [...new Set(schema[extensionKey])].map((name2, index) => ({
491
+ name: transformers.stringify(name2),
492
+ value: schema.enum?.[index],
493
+ format: isNumber(schema.enum?.[index]) ? "number" : "string"
494
+ }))
495
+ }
496
+ },
497
+ ...baseItems.filter(
498
+ (item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches
499
+ )
500
+ ];
501
+ });
502
+ if (schema.type === "number" || schema.type === "integer") {
503
+ const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
504
+ return [
505
+ {
506
+ keyword: schemaKeywords.enum,
507
+ args: {
508
+ name: enumName,
509
+ typeName,
510
+ asConst: true,
511
+ items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
512
+ name: name2,
513
+ value,
514
+ format: "number"
515
+ })) : [...new Set(schema.enum)].map((value) => {
516
+ return {
517
+ name: value,
518
+ value,
519
+ format: "number"
520
+ };
521
+ })
522
+ }
523
+ },
524
+ ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
525
+ ];
526
+ }
527
+ if (extensionEnums.length > 0 && extensionEnums[0]) {
528
+ return extensionEnums[0];
529
+ }
530
+ return [
531
+ {
532
+ keyword: schemaKeywords.enum,
533
+ args: {
534
+ name: enumName,
535
+ typeName,
536
+ asConst: false,
537
+ items: [...new Set(schema.enum)].map((value) => ({
538
+ name: transformers.stringify(value),
539
+ value,
540
+ format: isNumber(value) ? "number" : "string"
541
+ }))
542
+ }
543
+ },
544
+ ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
545
+ ];
546
+ }
547
+ if ("prefixItems" in schema) {
548
+ const prefixItems = schema.prefixItems;
549
+ return [
550
+ {
551
+ keyword: schemaKeywords.tuple,
552
+ args: prefixItems.map((item) => {
553
+ return this.parse({ schema: item, name, parentName })[0];
554
+ }).filter(Boolean)
555
+ },
556
+ ...baseItems
557
+ ];
558
+ }
559
+ if (version === "3.1" && "const" in schema) {
560
+ if (schema["const"]) {
561
+ return [
562
+ {
563
+ keyword: schemaKeywords.const,
564
+ args: {
565
+ name: schema["const"],
566
+ format: typeof schema["const"] === "number" ? "number" : "string",
567
+ value: schema["const"]
568
+ }
569
+ },
570
+ ...baseItems
571
+ ];
572
+ }
573
+ return [{ keyword: schemaKeywords.null }];
574
+ }
575
+ if (schema.format) {
576
+ switch (schema.format) {
577
+ case "binary":
578
+ baseItems.push({ keyword: schemaKeywords.blob });
579
+ return baseItems;
580
+ case "date-time":
581
+ if (options.dateType) {
582
+ if (options.dateType === "date") {
583
+ baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
584
+ return baseItems;
585
+ }
586
+ if (options.dateType === "stringOffset") {
587
+ baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: true } });
588
+ return baseItems;
589
+ }
590
+ if (options.dateType === "stringLocal") {
591
+ baseItems.unshift({ keyword: schemaKeywords.datetime, args: { local: true } });
592
+ return baseItems;
593
+ }
594
+ baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: false } });
595
+ return baseItems;
596
+ }
597
+ break;
598
+ case "date":
599
+ if (options.dateType) {
600
+ if (options.dateType === "date") {
601
+ baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
602
+ return baseItems;
603
+ }
604
+ baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "string" } });
605
+ return baseItems;
606
+ }
607
+ break;
608
+ case "time":
609
+ if (options.dateType) {
610
+ if (options.dateType === "date") {
611
+ baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "date" } });
612
+ return baseItems;
613
+ }
614
+ baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "string" } });
615
+ return baseItems;
616
+ }
617
+ break;
618
+ case "uuid":
619
+ baseItems.unshift({ keyword: schemaKeywords.uuid });
620
+ break;
621
+ case "email":
622
+ case "idn-email":
623
+ baseItems.unshift({ keyword: schemaKeywords.email });
624
+ break;
625
+ case "uri":
626
+ case "ipv4":
627
+ case "ipv6":
628
+ case "uri-reference":
629
+ case "hostname":
630
+ case "idn-hostname":
631
+ baseItems.unshift({ keyword: schemaKeywords.url });
632
+ break;
633
+ default:
634
+ break;
635
+ }
636
+ }
637
+ if ("items" in schema || schema.type === "array") {
638
+ const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
639
+ const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
640
+ const items = this.parse({ schema: "items" in schema ? schema.items : [], name, parentName });
641
+ return [
642
+ {
643
+ keyword: schemaKeywords.array,
644
+ args: {
645
+ items,
646
+ min: min2,
647
+ max: max2
648
+ }
649
+ },
650
+ ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
651
+ ];
652
+ }
653
+ if (schema.properties || schema.additionalProperties) {
654
+ return [...__privateMethod(this, _parseProperties, parseProperties_fn).call(this, { schema, name }), ...baseItems];
655
+ }
656
+ if (schema.type) {
657
+ if (Array.isArray(schema.type)) {
658
+ const [type] = schema.type;
659
+ return [
660
+ ...this.parse({
661
+ schema: {
662
+ ...schema,
663
+ type
664
+ },
665
+ name,
666
+ parentName
667
+ }),
668
+ ...baseItems
669
+ ].filter(Boolean);
670
+ }
671
+ return [{ keyword: schema.type }, ...baseItems];
672
+ }
673
+ return [{ keyword: unknownReturn }];
674
+ };
675
+ var SchemaGenerator = _SchemaGenerator;
676
+
677
+ export {
678
+ schemaKeywords,
679
+ isKeyword,
680
+ SchemaGenerator
681
+ };
682
+ //# sourceMappingURL=chunk-QLNCBDLM.js.map