@kubb/plugin-oas 3.0.0-alpha.3 → 3.0.0-alpha.30

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