@kubb/plugin-oas 3.16.2 → 3.16.4

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 (110) hide show
  1. package/dist/Oas-CuqAnIw-.js +60 -0
  2. package/dist/Oas-CuqAnIw-.js.map +1 -0
  3. package/dist/Oas-Cv_pyXRM.cjs +78 -0
  4. package/dist/Oas-Cv_pyXRM.cjs.map +1 -0
  5. package/dist/OperationGenerator-CgbXErhW.d.cts +900 -0
  6. package/dist/OperationGenerator-OtLcGk2y.d.ts +900 -0
  7. package/dist/Schema-DJshqHto.d.cts +38 -0
  8. package/dist/Schema-DOXGUW1m.d.ts +38 -0
  9. package/dist/SchemaGenerator-8205BXCp.cjs +942 -0
  10. package/dist/SchemaGenerator-8205BXCp.cjs.map +1 -0
  11. package/dist/SchemaGenerator-B8Io6kky.js +930 -0
  12. package/dist/SchemaGenerator-B8Io6kky.js.map +1 -0
  13. package/dist/SchemaMapper-BaZQKrQB.js +54 -0
  14. package/dist/SchemaMapper-BaZQKrQB.js.map +1 -0
  15. package/dist/SchemaMapper-BiagBQN4.d.cts +388 -0
  16. package/dist/SchemaMapper-C2J2d3o4.d.ts +388 -0
  17. package/dist/SchemaMapper-D8J0V9Pj.cjs +66 -0
  18. package/dist/SchemaMapper-D8J0V9Pj.cjs.map +1 -0
  19. package/dist/chunk-CUT6urMc.cjs +30 -0
  20. package/dist/components.cjs +4 -19
  21. package/dist/components.d.cts +42 -35
  22. package/dist/components.d.ts +42 -35
  23. package/dist/components.js +3 -3
  24. package/dist/generators-BhLMlRNk.js +137 -0
  25. package/dist/generators-BhLMlRNk.js.map +1 -0
  26. package/dist/generators-DLH2kvlh.cjs +155 -0
  27. package/dist/generators-DLH2kvlh.cjs.map +1 -0
  28. package/dist/generators.cjs +4 -13
  29. package/dist/generators.d.cts +5 -7
  30. package/dist/generators.d.ts +5 -7
  31. package/dist/generators.js +5 -5
  32. package/dist/getFooter-BChY2kC1.cjs +43 -0
  33. package/dist/getFooter-BChY2kC1.cjs.map +1 -0
  34. package/dist/getFooter-T7_pZ6f8.js +31 -0
  35. package/dist/getFooter-T7_pZ6f8.js.map +1 -0
  36. package/dist/getSchemas-D8mP129c.cjs +67 -0
  37. package/dist/getSchemas-D8mP129c.cjs.map +1 -0
  38. package/dist/getSchemas-WoSBIxG8.js +55 -0
  39. package/dist/getSchemas-WoSBIxG8.js.map +1 -0
  40. package/dist/hooks.cjs +213 -195
  41. package/dist/hooks.cjs.map +1 -1
  42. package/dist/hooks.d.cts +91 -86
  43. package/dist/hooks.d.ts +91 -86
  44. package/dist/hooks.js +212 -193
  45. package/dist/hooks.js.map +1 -1
  46. package/dist/index.cjs +280 -342
  47. package/dist/index.cjs.map +1 -1
  48. package/dist/index.d.cts +7 -10
  49. package/dist/index.d.ts +7 -10
  50. package/dist/index.js +274 -318
  51. package/dist/index.js.map +1 -1
  52. package/dist/mocks.cjs +802 -737
  53. package/dist/mocks.cjs.map +1 -1
  54. package/dist/mocks.d.cts +12 -11
  55. package/dist/mocks.d.ts +12 -11
  56. package/dist/mocks.js +802 -735
  57. package/dist/mocks.js.map +1 -1
  58. package/dist/parseFromConfig-CMNGsef2.cjs +33 -0
  59. package/dist/parseFromConfig-CMNGsef2.cjs.map +1 -0
  60. package/dist/parseFromConfig-yAiFK03V.js +27 -0
  61. package/dist/parseFromConfig-yAiFK03V.js.map +1 -0
  62. package/dist/utils.cjs +58 -74
  63. package/dist/utils.cjs.map +1 -1
  64. package/dist/utils.d.cts +96 -42
  65. package/dist/utils.d.ts +96 -42
  66. package/dist/utils.js +47 -46
  67. package/dist/utils.js.map +1 -1
  68. package/package.json +26 -34
  69. package/src/components/Operation.tsx +1 -2
  70. package/src/mocks/schemas.ts +39 -0
  71. package/src/utils/getBanner.ts +5 -5
  72. package/src/utils/getFooter.ts +4 -4
  73. package/dist/OperationGenerator-C7NPZtOM.d.ts +0 -288
  74. package/dist/OperationGenerator-DJE2XQ83.d.cts +0 -288
  75. package/dist/Schema-AjebpeVY.d.ts +0 -32
  76. package/dist/Schema-M6983FL1.d.cts +0 -32
  77. package/dist/SchemaMapper-B21ZmWag.d.cts +0 -275
  78. package/dist/SchemaMapper-B21ZmWag.d.ts +0 -275
  79. package/dist/chunk-6S7YFY6F.js +0 -33
  80. package/dist/chunk-6S7YFY6F.js.map +0 -1
  81. package/dist/chunk-76E35IZ2.js +0 -56
  82. package/dist/chunk-76E35IZ2.js.map +0 -1
  83. package/dist/chunk-7RFNM43R.cjs +0 -41
  84. package/dist/chunk-7RFNM43R.cjs.map +0 -1
  85. package/dist/chunk-DTD4ZUDA.cjs +0 -36
  86. package/dist/chunk-DTD4ZUDA.cjs.map +0 -1
  87. package/dist/chunk-G3FDK7YW.js +0 -35
  88. package/dist/chunk-G3FDK7YW.js.map +0 -1
  89. package/dist/chunk-JNN4JPWK.js +0 -28
  90. package/dist/chunk-JNN4JPWK.js.map +0 -1
  91. package/dist/chunk-MBX66JAT.js +0 -93
  92. package/dist/chunk-MBX66JAT.js.map +0 -1
  93. package/dist/chunk-NC5PWNEF.js +0 -866
  94. package/dist/chunk-NC5PWNEF.js.map +0 -1
  95. package/dist/chunk-PORSNYI5.js +0 -47
  96. package/dist/chunk-PORSNYI5.js.map +0 -1
  97. package/dist/chunk-QJMOOF2A.cjs +0 -97
  98. package/dist/chunk-QJMOOF2A.cjs.map +0 -1
  99. package/dist/chunk-RKHCI3WI.cjs +0 -1002
  100. package/dist/chunk-RKHCI3WI.cjs.map +0 -1
  101. package/dist/chunk-YWMMI3MO.cjs +0 -59
  102. package/dist/chunk-YWMMI3MO.cjs.map +0 -1
  103. package/dist/chunk-Z2NREI4X.cjs +0 -32
  104. package/dist/chunk-Z2NREI4X.cjs.map +0 -1
  105. package/dist/chunk-ZVFL3NXX.cjs +0 -50
  106. package/dist/chunk-ZVFL3NXX.cjs.map +0 -1
  107. package/dist/components.cjs.map +0 -1
  108. package/dist/components.js.map +0 -1
  109. package/dist/generators.cjs.map +0 -1
  110. package/dist/generators.js.map +0 -1
@@ -1,1002 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkYWMMI3MO_cjs = require('./chunk-YWMMI3MO.cjs');
4
- var chunkZVFL3NXX_cjs = require('./chunk-ZVFL3NXX.cjs');
5
- var core = require('@kubb/core');
6
- var transformers = require('@kubb/core/transformers');
7
- var utils = require('@kubb/core/utils');
8
- var oas = require('@kubb/oas');
9
- var remeda = require('remeda');
10
-
11
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
-
13
- var transformers__default = /*#__PURE__*/_interopDefault(transformers);
14
-
15
- // ../../node_modules/.pnpm/yocto-queue@1.1.1/node_modules/yocto-queue/index.js
16
- var Node = class {
17
- value;
18
- next;
19
- constructor(value) {
20
- this.value = value;
21
- }
22
- };
23
- var Queue = class {
24
- #head;
25
- #tail;
26
- #size;
27
- constructor() {
28
- this.clear();
29
- }
30
- enqueue(value) {
31
- const node = new Node(value);
32
- if (this.#head) {
33
- this.#tail.next = node;
34
- this.#tail = node;
35
- } else {
36
- this.#head = node;
37
- this.#tail = node;
38
- }
39
- this.#size++;
40
- }
41
- dequeue() {
42
- const current = this.#head;
43
- if (!current) {
44
- return;
45
- }
46
- this.#head = this.#head.next;
47
- this.#size--;
48
- return current.value;
49
- }
50
- peek() {
51
- if (!this.#head) {
52
- return;
53
- }
54
- return this.#head.value;
55
- }
56
- clear() {
57
- this.#head = void 0;
58
- this.#tail = void 0;
59
- this.#size = 0;
60
- }
61
- get size() {
62
- return this.#size;
63
- }
64
- *[Symbol.iterator]() {
65
- let current = this.#head;
66
- while (current) {
67
- yield current.value;
68
- current = current.next;
69
- }
70
- }
71
- };
72
-
73
- // ../../node_modules/.pnpm/p-limit@6.2.0/node_modules/p-limit/index.js
74
- function pLimit(concurrency) {
75
- validateConcurrency(concurrency);
76
- const queue = new Queue();
77
- let activeCount = 0;
78
- const resumeNext = () => {
79
- if (activeCount < concurrency && queue.size > 0) {
80
- queue.dequeue()();
81
- activeCount++;
82
- }
83
- };
84
- const next = () => {
85
- activeCount--;
86
- resumeNext();
87
- };
88
- const run = async (function_, resolve, arguments_) => {
89
- const result = (async () => function_(...arguments_))();
90
- resolve(result);
91
- try {
92
- await result;
93
- } catch {
94
- }
95
- next();
96
- };
97
- const enqueue = (function_, resolve, arguments_) => {
98
- new Promise((internalResolve) => {
99
- queue.enqueue(internalResolve);
100
- }).then(
101
- run.bind(void 0, function_, resolve, arguments_)
102
- );
103
- (async () => {
104
- await Promise.resolve();
105
- if (activeCount < concurrency) {
106
- resumeNext();
107
- }
108
- })();
109
- };
110
- const generator = (function_, ...arguments_) => new Promise((resolve) => {
111
- enqueue(function_, resolve, arguments_);
112
- });
113
- Object.defineProperties(generator, {
114
- activeCount: {
115
- get: () => activeCount
116
- },
117
- pendingCount: {
118
- get: () => queue.size
119
- },
120
- clearQueue: {
121
- value() {
122
- queue.clear();
123
- }
124
- },
125
- concurrency: {
126
- get: () => concurrency,
127
- set(newConcurrency) {
128
- validateConcurrency(newConcurrency);
129
- concurrency = newConcurrency;
130
- queueMicrotask(() => {
131
- while (activeCount < concurrency && queue.size > 0) {
132
- resumeNext();
133
- }
134
- });
135
- }
136
- }
137
- });
138
- return generator;
139
- }
140
- function validateConcurrency(concurrency) {
141
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
142
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
143
- }
144
- }
145
- var SchemaGenerator = class _SchemaGenerator extends core.BaseGenerator {
146
- // Collect the types of all referenced schemas, so we can export them later
147
- refs = {};
148
- // Keep track of already used type aliases
149
- #usedAliasNames = {};
150
- /**
151
- * Creates a type node from a given schema.
152
- * Delegates to getBaseTypeFromSchema internally and
153
- * optionally adds a union with null.
154
- */
155
- parse(props) {
156
- const options = this.#getOptions(props);
157
- const defaultSchemas = this.#parseSchemaObject(props);
158
- const schemas = options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || [];
159
- return remeda.uniqueWith(schemas, remeda.isDeepEqual);
160
- }
161
- deepSearch(tree, keyword) {
162
- return _SchemaGenerator.deepSearch(tree, keyword);
163
- }
164
- find(tree, keyword) {
165
- return _SchemaGenerator.find(tree, keyword);
166
- }
167
- static deepSearch(tree, keyword) {
168
- const foundItems = [];
169
- tree?.forEach((schema) => {
170
- if (schema.keyword === keyword) {
171
- foundItems.push(schema);
172
- }
173
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.object)) {
174
- Object.values(schema.args?.properties || {}).forEach((entrySchema) => {
175
- foundItems.push(..._SchemaGenerator.deepSearch(entrySchema, keyword));
176
- });
177
- Object.values(schema.args?.additionalProperties || {}).forEach((entrySchema) => {
178
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
179
- });
180
- }
181
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.array)) {
182
- schema.args.items.forEach((entrySchema) => {
183
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
184
- });
185
- }
186
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.and)) {
187
- schema.args.forEach((entrySchema) => {
188
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
189
- });
190
- }
191
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.tuple)) {
192
- schema.args.items.forEach((entrySchema) => {
193
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
194
- });
195
- }
196
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.union)) {
197
- schema.args.forEach((entrySchema) => {
198
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
199
- });
200
- }
201
- });
202
- return foundItems;
203
- }
204
- static findInObject(tree, keyword) {
205
- let foundItem;
206
- tree?.forEach((schema) => {
207
- if (!foundItem && schema.keyword === keyword) {
208
- foundItem = schema;
209
- }
210
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.object)) {
211
- Object.values(schema.args?.properties || {}).forEach((entrySchema) => {
212
- if (!foundItem) {
213
- foundItem = _SchemaGenerator.find(entrySchema, keyword);
214
- }
215
- });
216
- Object.values(schema.args?.additionalProperties || {}).forEach((entrySchema) => {
217
- if (!foundItem) {
218
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
219
- }
220
- });
221
- }
222
- });
223
- return foundItem;
224
- }
225
- static find(tree, keyword) {
226
- let foundItem;
227
- tree?.forEach((schema) => {
228
- if (!foundItem && schema.keyword === keyword) {
229
- foundItem = schema;
230
- }
231
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.array)) {
232
- schema.args.items.forEach((entrySchema) => {
233
- if (!foundItem) {
234
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
235
- }
236
- });
237
- }
238
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.and)) {
239
- schema.args.forEach((entrySchema) => {
240
- if (!foundItem) {
241
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
242
- }
243
- });
244
- }
245
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.tuple)) {
246
- schema.args.items.forEach((entrySchema) => {
247
- if (!foundItem) {
248
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
249
- }
250
- });
251
- }
252
- if (chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.union)) {
253
- schema.args.forEach((entrySchema) => {
254
- if (!foundItem) {
255
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
256
- }
257
- });
258
- }
259
- });
260
- return foundItem;
261
- }
262
- static combineObjects(tree) {
263
- if (!tree) {
264
- return [];
265
- }
266
- return tree.map((schema) => {
267
- if (!chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.and)) {
268
- return schema;
269
- }
270
- let mergedProperties = null;
271
- let mergedAdditionalProps = [];
272
- const newArgs = [];
273
- for (const subSchema of schema.args) {
274
- if (chunkYWMMI3MO_cjs.isKeyword(subSchema, chunkYWMMI3MO_cjs.schemaKeywords.object)) {
275
- const { properties = {}, additionalProperties = [] } = subSchema.args ?? {};
276
- if (!mergedProperties) {
277
- mergedProperties = {};
278
- }
279
- for (const [key, value] of Object.entries(properties)) {
280
- mergedProperties[key] = value;
281
- }
282
- if (additionalProperties.length > 0) {
283
- mergedAdditionalProps = additionalProperties;
284
- }
285
- } else {
286
- newArgs.push(subSchema);
287
- }
288
- }
289
- if (mergedProperties) {
290
- newArgs.push({
291
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.object,
292
- args: {
293
- properties: mergedProperties,
294
- additionalProperties: mergedAdditionalProps
295
- }
296
- });
297
- }
298
- return {
299
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
300
- args: newArgs
301
- };
302
- });
303
- }
304
- #getUsedEnumNames(props) {
305
- const options = this.#getOptions(props);
306
- return options.usedEnumNames || {};
307
- }
308
- #getOptions({ name }) {
309
- const { override = [] } = this.context;
310
- return {
311
- ...this.options,
312
- ...override.find(({ pattern, type }) => {
313
- if (name && type === "schemaName") {
314
- return !!name.match(pattern);
315
- }
316
- return false;
317
- })?.options || {}
318
- };
319
- }
320
- #getUnknownType(props) {
321
- const options = this.#getOptions(props);
322
- if (options.unknownType === "any") {
323
- return chunkYWMMI3MO_cjs.schemaKeywords.any;
324
- }
325
- if (options.unknownType === "void") {
326
- return chunkYWMMI3MO_cjs.schemaKeywords.void;
327
- }
328
- return chunkYWMMI3MO_cjs.schemaKeywords.unknown;
329
- }
330
- #getEmptyType(props) {
331
- const options = this.#getOptions(props);
332
- if (options.emptySchemaType === "any") {
333
- return chunkYWMMI3MO_cjs.schemaKeywords.any;
334
- }
335
- if (options.emptySchemaType === "void") {
336
- return chunkYWMMI3MO_cjs.schemaKeywords.void;
337
- }
338
- return chunkYWMMI3MO_cjs.schemaKeywords.unknown;
339
- }
340
- /**
341
- * Recursively creates a type literal with the given props.
342
- */
343
- #parseProperties({ schemaObject, name }) {
344
- const properties = schemaObject?.properties || {};
345
- const additionalProperties = schemaObject?.additionalProperties;
346
- const required = schemaObject?.required;
347
- const propertiesSchemas = Object.keys(properties).map((propertyName) => {
348
- const validationFunctions = [];
349
- const propertySchema = properties[propertyName];
350
- const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
351
- const nullable = propertySchema.nullable ?? propertySchema["x-nullable"] ?? false;
352
- validationFunctions.push(...this.parse({ schemaObject: propertySchema, name: propertyName, parentName: name }));
353
- validationFunctions.push({
354
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.name,
355
- args: propertyName
356
- });
357
- if (!isRequired && nullable) {
358
- validationFunctions.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullish });
359
- } else if (!isRequired) {
360
- validationFunctions.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.optional });
361
- }
362
- return {
363
- [propertyName]: validationFunctions
364
- };
365
- }).reduce((acc, curr) => ({ ...acc, ...curr }), {});
366
- let additionalPropertiesSchemas = [];
367
- if (additionalProperties) {
368
- additionalPropertiesSchemas = additionalProperties === true || !Object.keys(additionalProperties).length ? [{ keyword: this.#getUnknownType({ schemaObject, name }) }] : this.parse({ schemaObject: additionalProperties, parentName: name });
369
- }
370
- return [
371
- {
372
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.object,
373
- args: {
374
- properties: propertiesSchemas,
375
- additionalProperties: additionalPropertiesSchemas
376
- }
377
- }
378
- ];
379
- }
380
- /**
381
- * Create a type alias for the schema referenced by the given ReferenceObject
382
- */
383
- #getRefAlias(schemaObject, name) {
384
- const { $ref } = schemaObject;
385
- const ref = this.refs[$ref];
386
- if (ref) {
387
- const dereferencedSchema = this.context.oas.dereferenceWithRef(schemaObject);
388
- if (dereferencedSchema && oas.isDiscriminator(dereferencedSchema)) {
389
- const [key] = Object.entries(dereferencedSchema.discriminator.mapping || {}).find(([_key, value]) => value.replace(/.+\//, "") === name) || [];
390
- if (key) {
391
- return [
392
- {
393
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
394
- args: [
395
- {
396
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.ref,
397
- args: { name: ref.propertyName, $ref, path: ref.path, isImportable: !!this.context.oas.get($ref) }
398
- },
399
- {
400
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.object,
401
- args: {
402
- properties: {
403
- [dereferencedSchema.discriminator.propertyName]: [
404
- {
405
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.const,
406
- args: {
407
- name: key,
408
- format: "string",
409
- value: key
410
- }
411
- }
412
- ]
413
- }
414
- }
415
- }
416
- ]
417
- }
418
- ];
419
- }
420
- }
421
- return [
422
- {
423
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.ref,
424
- args: { name: ref.propertyName, $ref, path: ref.path, isImportable: !!this.context.oas.get($ref) }
425
- }
426
- ];
427
- }
428
- const originalName = utils.getUniqueName($ref.replace(/.+\//, ""), this.#usedAliasNames);
429
- const propertyName = this.context.pluginManager.resolveName({
430
- name: originalName,
431
- pluginKey: this.context.plugin.key,
432
- type: "function"
433
- });
434
- const fileName = this.context.pluginManager.resolveName({
435
- name: originalName,
436
- pluginKey: this.context.plugin.key,
437
- type: "file"
438
- });
439
- const file = this.context.pluginManager.getFile({
440
- name: fileName,
441
- pluginKey: this.context.plugin.key,
442
- extname: ".ts"
443
- });
444
- this.refs[$ref] = {
445
- propertyName,
446
- originalName,
447
- path: file.path
448
- };
449
- return this.#getRefAlias(schemaObject, name);
450
- }
451
- #getParsedSchemaObject(schema) {
452
- return chunkZVFL3NXX_cjs.getSchemaFactory(this.context.oas)(schema);
453
- }
454
- #addDiscriminatorToSchema({
455
- schema,
456
- schemaObject,
457
- discriminator
458
- }) {
459
- if (!chunkYWMMI3MO_cjs.isKeyword(schema, chunkYWMMI3MO_cjs.schemaKeywords.union)) {
460
- return schema;
461
- }
462
- const objectPropertySchema = _SchemaGenerator.find(this.parse({ schemaObject }), chunkYWMMI3MO_cjs.schemaKeywords.object);
463
- return {
464
- ...schema,
465
- args: Object.entries(discriminator.mapping || {}).map(([key, value]) => {
466
- const arg = schema.args.find((item) => chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.ref) && item.args.$ref === value);
467
- return {
468
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
469
- args: [
470
- arg,
471
- {
472
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.object,
473
- args: {
474
- properties: {
475
- ...objectPropertySchema?.args?.properties || {},
476
- [discriminator.propertyName]: [
477
- {
478
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.const,
479
- args: {
480
- name: key,
481
- format: "string",
482
- value: key
483
- }
484
- },
485
- //enum and literal will conflict
486
- ...objectPropertySchema?.args?.properties[discriminator.propertyName] || []
487
- ].filter((item) => !chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.enum))
488
- }
489
- }
490
- }
491
- ]
492
- };
493
- })
494
- };
495
- }
496
- /**
497
- * This is the very core of the OpenAPI to TS conversion - it takes a
498
- * schema and returns the appropriate type.
499
- */
500
- #parseSchemaObject({ schemaObject: _schemaObject, name, parentName }) {
501
- const { schemaObject, version } = this.#getParsedSchemaObject(_schemaObject);
502
- const options = this.#getOptions({ schemaObject, name });
503
- const emptyType = this.#getEmptyType({ schemaObject, name });
504
- if (!schemaObject) {
505
- return [{ keyword: emptyType }];
506
- }
507
- const baseItems = [
508
- {
509
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.schema,
510
- args: {
511
- type: schemaObject.type,
512
- format: schemaObject.format
513
- }
514
- }
515
- ];
516
- const min = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
517
- const max = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
518
- const nullable = oas.isNullable(schemaObject);
519
- const defaultNullAndNullable = schemaObject.default === null && nullable;
520
- if (schemaObject.default !== void 0 && !defaultNullAndNullable && !Array.isArray(schemaObject.default)) {
521
- if (typeof schemaObject.default === "string") {
522
- baseItems.push({
523
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.default,
524
- args: transformers__default.default.stringify(schemaObject.default)
525
- });
526
- } else if (typeof schemaObject.default === "boolean") {
527
- baseItems.push({
528
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.default,
529
- args: schemaObject.default ?? false
530
- });
531
- } else {
532
- baseItems.push({
533
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.default,
534
- args: schemaObject.default
535
- });
536
- }
537
- }
538
- if (schemaObject.deprecated) {
539
- baseItems.push({
540
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.deprecated
541
- });
542
- }
543
- if (schemaObject.description) {
544
- baseItems.push({
545
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.describe,
546
- args: schemaObject.description
547
- });
548
- }
549
- if (max !== void 0) {
550
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.max, args: max });
551
- }
552
- if (min !== void 0) {
553
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.min, args: min });
554
- }
555
- if (nullable) {
556
- baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullable });
557
- }
558
- if (schemaObject.type && Array.isArray(schemaObject.type)) {
559
- const items = schemaObject.type.filter((value) => value !== "null");
560
- const hasNull = schemaObject.type.includes("null");
561
- if (hasNull && !nullable) {
562
- baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullable });
563
- }
564
- if (items.length > 1) {
565
- const parsedItems = [
566
- {
567
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.union,
568
- args: items.map(
569
- (item) => this.parse({
570
- schemaObject: { ...schemaObject, type: item },
571
- name,
572
- parentName
573
- })[0]
574
- ).filter(Boolean).filter((item) => !chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.unknown)).map((item) => chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.object) ? { ...item, args: { ...item.args, strict: true } } : item)
575
- }
576
- ];
577
- return [...parsedItems, ...baseItems].filter(Boolean);
578
- }
579
- }
580
- if (schemaObject.readOnly) {
581
- baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.readOnly });
582
- }
583
- if (schemaObject.writeOnly) {
584
- baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.writeOnly });
585
- }
586
- if (oas.isReference(schemaObject)) {
587
- return [
588
- ...this.#getRefAlias(schemaObject, name),
589
- schemaObject.description && {
590
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.describe,
591
- args: schemaObject.description
592
- },
593
- schemaObject.pattern && schemaObject.type === "string" && {
594
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.matches,
595
- args: schemaObject.pattern
596
- },
597
- nullable && { keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullable },
598
- schemaObject.readOnly && { keyword: chunkYWMMI3MO_cjs.schemaKeywords.readOnly },
599
- schemaObject.writeOnly && { keyword: chunkYWMMI3MO_cjs.schemaKeywords.writeOnly },
600
- {
601
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.schema,
602
- args: {
603
- type: schemaObject.type,
604
- format: schemaObject.format
605
- }
606
- }
607
- ].filter(Boolean);
608
- }
609
- if (schemaObject.oneOf || schemaObject.anyOf) {
610
- const schemaWithoutOneOf = { ...schemaObject, oneOf: void 0, anyOf: void 0 };
611
- const discriminator = this.context.oas.getDiscriminator(schemaObject);
612
- const union = {
613
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.union,
614
- args: (schemaObject.oneOf || schemaObject.anyOf).map((item) => {
615
- return item && this.parse({ schemaObject: item, name, parentName })[0];
616
- }).filter(Boolean).filter((item) => !chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.unknown))
617
- };
618
- if (discriminator) {
619
- if (this.context) return [this.#addDiscriminatorToSchema({ schemaObject: schemaWithoutOneOf, schema: union, discriminator }), ...baseItems];
620
- }
621
- if (schemaWithoutOneOf.properties) {
622
- const propertySchemas = this.parse({ schemaObject: schemaWithoutOneOf, name, parentName });
623
- union.args = [
624
- ...union.args.map((arg) => {
625
- return {
626
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
627
- args: [arg, ...propertySchemas]
628
- };
629
- })
630
- ];
631
- return [union, ...baseItems];
632
- }
633
- return [union, ...baseItems];
634
- }
635
- if (schemaObject.allOf) {
636
- const schemaWithoutAllOf = { ...schemaObject, allOf: void 0 };
637
- const and = {
638
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.and,
639
- args: schemaObject.allOf.map((item) => {
640
- return item && this.parse({ schemaObject: item, name, parentName })[0];
641
- }).filter(Boolean).filter((item) => !chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.unknown))
642
- };
643
- if (schemaWithoutAllOf.required?.length) {
644
- const allOfItems = schemaObject.allOf;
645
- const resolvedSchemas = [];
646
- for (const item of allOfItems) {
647
- const resolved = oas.isReference(item) ? this.context.oas.get(item.$ref) : item;
648
- if (resolved) {
649
- resolvedSchemas.push(resolved);
650
- }
651
- }
652
- const existingKeys = schemaWithoutAllOf.properties ? new Set(Object.keys(schemaWithoutAllOf.properties)) : null;
653
- const parsedItems = [];
654
- for (const key of schemaWithoutAllOf.required) {
655
- if (existingKeys?.has(key)) {
656
- continue;
657
- }
658
- for (const schema of resolvedSchemas) {
659
- if (schema.properties?.[key]) {
660
- parsedItems.push({
661
- properties: {
662
- [key]: schema.properties[key]
663
- },
664
- required: [key]
665
- });
666
- break;
667
- }
668
- }
669
- }
670
- for (const item of parsedItems) {
671
- const parsed = this.parse({ schemaObject: item, name, parentName });
672
- if (Array.isArray(parsed)) {
673
- and.args = and.args ? and.args.concat(parsed) : parsed;
674
- }
675
- }
676
- }
677
- if (schemaWithoutAllOf.properties) {
678
- and.args = [...and.args || [], ...this.parse({ schemaObject: schemaWithoutAllOf, name, parentName })];
679
- }
680
- return _SchemaGenerator.combineObjects([and, ...baseItems]);
681
- }
682
- if (schemaObject.enum) {
683
- if (options.enumSuffix === "") {
684
- this.context.pluginManager.logger.emit("info", "EnumSuffix set to an empty string does not work");
685
- }
686
- const enumName = utils.getUniqueName(transformers.pascalCase([parentName, name, options.enumSuffix].join(" ")), this.#getUsedEnumNames({ schemaObject, name }));
687
- const typeName = this.context.pluginManager.resolveName({
688
- name: enumName,
689
- pluginKey: this.context.plugin.key,
690
- type: "type"
691
- });
692
- const nullableEnum = schemaObject.enum.includes(null);
693
- if (nullableEnum) {
694
- baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.nullable });
695
- }
696
- const filteredValues = schemaObject.enum.filter((value) => value !== null);
697
- const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schemaObject).map((extensionKey) => {
698
- return [
699
- {
700
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.enum,
701
- args: {
702
- name,
703
- typeName,
704
- asConst: false,
705
- items: [...new Set(schemaObject[extensionKey])].map((name2, index) => ({
706
- name: transformers__default.default.stringify(name2),
707
- value: schemaObject.enum?.[index],
708
- format: remeda.isNumber(schemaObject.enum?.[index]) ? "number" : "string"
709
- }))
710
- }
711
- },
712
- ...baseItems.filter(
713
- (item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.matches
714
- )
715
- ];
716
- });
717
- if (schemaObject.type === "number" || schemaObject.type === "integer") {
718
- const enumNames = extensionEnums[0]?.find((item) => chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.enum));
719
- return [
720
- {
721
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.enum,
722
- args: {
723
- name: enumName,
724
- typeName,
725
- asConst: true,
726
- items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
727
- name: name2,
728
- value,
729
- format: "number"
730
- })) : [...new Set(filteredValues)].map((value) => {
731
- return {
732
- name: value,
733
- value,
734
- format: "number"
735
- };
736
- })
737
- }
738
- },
739
- ...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.matches)
740
- ];
741
- }
742
- if (schemaObject.type === "boolean") {
743
- const enumNames = extensionEnums[0]?.find((item) => chunkYWMMI3MO_cjs.isKeyword(item, chunkYWMMI3MO_cjs.schemaKeywords.enum));
744
- return [
745
- {
746
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.enum,
747
- args: {
748
- name: enumName,
749
- typeName,
750
- asConst: true,
751
- items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
752
- name: name2,
753
- value,
754
- format: "boolean"
755
- })) : [...new Set(filteredValues)].map((value) => {
756
- return {
757
- name: value,
758
- value,
759
- format: "boolean"
760
- };
761
- })
762
- }
763
- },
764
- ...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.matches)
765
- ];
766
- }
767
- if (extensionEnums.length > 0 && extensionEnums[0]) {
768
- return extensionEnums[0];
769
- }
770
- return [
771
- {
772
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.enum,
773
- args: {
774
- name: enumName,
775
- typeName,
776
- asConst: false,
777
- items: [...new Set(filteredValues)].map((value) => ({
778
- name: transformers__default.default.stringify(value),
779
- value,
780
- format: remeda.isNumber(value) ? "number" : "string"
781
- }))
782
- }
783
- },
784
- ...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.matches)
785
- ];
786
- }
787
- if ("prefixItems" in schemaObject) {
788
- const prefixItems = schemaObject.prefixItems;
789
- const items = "items" in schemaObject ? schemaObject.items : [];
790
- const min2 = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
791
- const max2 = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
792
- return [
793
- {
794
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.tuple,
795
- args: {
796
- min: min2,
797
- max: max2,
798
- items: prefixItems.map((item) => {
799
- return this.parse({ schemaObject: item, name, parentName })[0];
800
- }).filter(Boolean),
801
- rest: this.parse({
802
- schemaObject: items,
803
- name,
804
- parentName
805
- })[0]
806
- }
807
- },
808
- ...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max)
809
- ];
810
- }
811
- if (version === "3.1" && "const" in schemaObject) {
812
- if (schemaObject["const"] === null) {
813
- return [{ keyword: chunkYWMMI3MO_cjs.schemaKeywords.null }];
814
- }
815
- if (schemaObject["const"] === void 0) {
816
- return [{ keyword: chunkYWMMI3MO_cjs.schemaKeywords.undefined }];
817
- }
818
- let format = typeof schemaObject["const"];
819
- if (format !== "number" && format !== "boolean") {
820
- format = "string";
821
- }
822
- return [
823
- {
824
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.const,
825
- args: {
826
- name: schemaObject["const"],
827
- format,
828
- value: schemaObject["const"]
829
- }
830
- },
831
- ...baseItems
832
- ];
833
- }
834
- if (schemaObject.format) {
835
- if (schemaObject.type === "integer" && (schemaObject.format === "int32" || schemaObject.format === "int64")) {
836
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.integer });
837
- return baseItems;
838
- }
839
- if (schemaObject.type === "number" && (schemaObject.format === "float" || schemaObject.format === "double")) {
840
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.number });
841
- return baseItems;
842
- }
843
- switch (schemaObject.format) {
844
- case "binary":
845
- baseItems.push({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.blob });
846
- return baseItems;
847
- case "date-time":
848
- if (options.dateType) {
849
- if (options.dateType === "date") {
850
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.date, args: { type: "date" } });
851
- return baseItems;
852
- }
853
- if (options.dateType === "stringOffset") {
854
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.datetime, args: { offset: true } });
855
- return baseItems;
856
- }
857
- if (options.dateType === "stringLocal") {
858
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.datetime, args: { local: true } });
859
- return baseItems;
860
- }
861
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.datetime, args: { offset: false } });
862
- return baseItems;
863
- }
864
- break;
865
- case "date":
866
- if (options.dateType) {
867
- if (options.dateType === "date") {
868
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.date, args: { type: "date" } });
869
- return baseItems;
870
- }
871
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.date, args: { type: "string" } });
872
- return baseItems;
873
- }
874
- break;
875
- case "time":
876
- if (options.dateType) {
877
- if (options.dateType === "date") {
878
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.time, args: { type: "date" } });
879
- return baseItems;
880
- }
881
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.time, args: { type: "string" } });
882
- return baseItems;
883
- }
884
- break;
885
- case "uuid":
886
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.uuid });
887
- return baseItems;
888
- case "email":
889
- case "idn-email":
890
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.email });
891
- return baseItems;
892
- case "uri":
893
- case "ipv4":
894
- case "ipv6":
895
- case "uri-reference":
896
- case "hostname":
897
- case "idn-hostname":
898
- baseItems.unshift({ keyword: chunkYWMMI3MO_cjs.schemaKeywords.url });
899
- return baseItems;
900
- }
901
- }
902
- if (schemaObject.pattern && schemaObject.type === "string") {
903
- baseItems.unshift({
904
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.matches,
905
- args: schemaObject.pattern
906
- });
907
- return baseItems;
908
- }
909
- if ("items" in schemaObject || schemaObject.type === "array") {
910
- const min2 = schemaObject.minimum ?? schemaObject.minLength ?? schemaObject.minItems ?? void 0;
911
- const max2 = schemaObject.maximum ?? schemaObject.maxLength ?? schemaObject.maxItems ?? void 0;
912
- const items = this.parse({ schemaObject: "items" in schemaObject ? schemaObject.items : [], name, parentName });
913
- const unique = !!schemaObject.uniqueItems;
914
- return [
915
- {
916
- keyword: chunkYWMMI3MO_cjs.schemaKeywords.array,
917
- args: {
918
- items,
919
- min: min2,
920
- max: max2,
921
- unique
922
- }
923
- },
924
- ...baseItems.filter((item) => item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.min && item.keyword !== chunkYWMMI3MO_cjs.schemaKeywords.max)
925
- ];
926
- }
927
- if (schemaObject.properties || schemaObject.additionalProperties) {
928
- if (oas.isDiscriminator(schemaObject)) {
929
- const schemaObjectOverriden = Object.keys(schemaObject.properties || {}).reduce((acc, propertyName) => {
930
- if (acc.properties?.[propertyName] && propertyName === schemaObject.discriminator.propertyName) {
931
- return {
932
- ...acc,
933
- properties: {
934
- ...acc.properties,
935
- [propertyName]: {
936
- ...acc.properties[propertyName] || {},
937
- enum: schemaObject.discriminator.mapping ? Object.keys(schemaObject.discriminator.mapping) : void 0
938
- }
939
- }
940
- };
941
- }
942
- return acc;
943
- }, schemaObject || {});
944
- return [
945
- ...this.#parseProperties({
946
- schemaObject: schemaObjectOverriden,
947
- name
948
- }),
949
- ...baseItems
950
- ];
951
- }
952
- return [...this.#parseProperties({ schemaObject, name }), ...baseItems];
953
- }
954
- if (schemaObject.type) {
955
- const type = Array.isArray(schemaObject.type) ? schemaObject.type.filter((item) => item !== "null")[0] : schemaObject.type;
956
- if (!["boolean", "object", "number", "string", "integer", "null"].includes(type)) {
957
- this.context.pluginManager.logger.emit("warning", `Schema type '${schemaObject.type}' is not valid for schema ${parentName}.${name}`);
958
- }
959
- return [{ keyword: type }, ...baseItems];
960
- }
961
- return [{ keyword: emptyType }];
962
- }
963
- async build(...generators) {
964
- const { oas, contentType, include } = this.context;
965
- const schemas = chunkZVFL3NXX_cjs.getSchemas({ oas, contentType, includes: include });
966
- const schemaEntries = Object.entries(schemas);
967
- const generatorLimit = pLimit(1);
968
- const schemaLimit = pLimit(10);
969
- const writeTasks = generators.map(
970
- (generator) => generatorLimit(async () => {
971
- const schemaTasks = schemaEntries.map(
972
- ([name, schemaObject]) => schemaLimit(async () => {
973
- const options = this.#getOptions({ name });
974
- const tree = this.parse({ name, schemaObject });
975
- const result = await generator.schema?.({
976
- instance: this,
977
- schema: {
978
- name,
979
- value: schemaObject,
980
- tree
981
- },
982
- options: {
983
- ...this.options,
984
- ...options
985
- }
986
- });
987
- return result ?? [];
988
- })
989
- );
990
- const schemaResults = await Promise.all(schemaTasks);
991
- return schemaResults.flat();
992
- })
993
- );
994
- const nestedResults = await Promise.all(writeTasks);
995
- return nestedResults.flat();
996
- }
997
- };
998
-
999
- exports.SchemaGenerator = SchemaGenerator;
1000
- exports.pLimit = pLimit;
1001
- //# sourceMappingURL=chunk-RKHCI3WI.cjs.map
1002
- //# sourceMappingURL=chunk-RKHCI3WI.cjs.map