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