@kubb/plugin-oas 3.0.0-alpha.2 → 3.0.0-alpha.21

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