@kubb/plugin-oas 3.16.1 → 3.16.3

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