@kubb/swagger-ts 1.15.0-canary.20231026T165055 → 1.15.0-canary.20231026T182535

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.
package/dist/hooks.cjs ADDED
@@ -0,0 +1,653 @@
1
+ 'use strict';
2
+
3
+ var hooks = require('@kubb/swagger/hooks');
4
+ var path = require('path');
5
+ var core = require('@kubb/core');
6
+ var utils = require('@kubb/core/utils');
7
+ var swagger = require('@kubb/swagger');
8
+ var changeCase = require('change-case');
9
+ var parser = require('@kubb/parser');
10
+ var factory = require('@kubb/parser/factory');
11
+ var utils$1 = require('@kubb/swagger/utils');
12
+
13
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
+
15
+ function _interopNamespace(e) {
16
+ if (e && e.__esModule) return e;
17
+ var n = Object.create(null);
18
+ if (e) {
19
+ Object.keys(e).forEach(function (k) {
20
+ if (k !== 'default') {
21
+ var d = Object.getOwnPropertyDescriptor(e, k);
22
+ Object.defineProperty(n, k, d.get ? d : {
23
+ enumerable: true,
24
+ get: function () { return e[k]; }
25
+ });
26
+ }
27
+ });
28
+ }
29
+ n.default = e;
30
+ return Object.freeze(n);
31
+ }
32
+
33
+ var path__default = /*#__PURE__*/_interopDefault(path);
34
+ var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
35
+
36
+ var __accessCheck = (obj, member, msg) => {
37
+ if (!member.has(obj))
38
+ throw TypeError("Cannot " + msg);
39
+ };
40
+ var __privateGet = (obj, member, getter) => {
41
+ __accessCheck(obj, member, "read from private field");
42
+ return getter ? getter.call(obj) : member.get(obj);
43
+ };
44
+ var __privateAdd = (obj, member, value) => {
45
+ if (member.has(obj))
46
+ throw TypeError("Cannot add the same private member more than once");
47
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
48
+ };
49
+ var __privateMethod = (obj, member, method) => {
50
+ __accessCheck(obj, member, "access private method");
51
+ return method;
52
+ };
53
+ var _usedAliasNames, _caseOptions, _getTypeFromSchema, getTypeFromSchema_fn, _getTypeFromProperties, getTypeFromProperties_fn, _getRefAlias, getRefAlias_fn, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn;
54
+ var TypeGenerator = class extends core.SchemaGenerator {
55
+ constructor(options = {
56
+ usedEnumNames: {},
57
+ withJSDocs: true,
58
+ resolveName: ({ name }) => name,
59
+ enumType: "asConst",
60
+ dateType: "string",
61
+ optionalType: "questionToken"
62
+ }) {
63
+ super(options);
64
+ /**
65
+ * Creates a type node from a given schema.
66
+ * Delegates to getBaseTypeFromSchema internally and
67
+ * optionally adds a union with null.
68
+ */
69
+ __privateAdd(this, _getTypeFromSchema);
70
+ /**
71
+ * Recursively creates a type literal with the given props.
72
+ */
73
+ __privateAdd(this, _getTypeFromProperties);
74
+ /**
75
+ * Create a type alias for the schema referenced by the given ReferenceObject
76
+ */
77
+ __privateAdd(this, _getRefAlias);
78
+ /**
79
+ * This is the very core of the OpenAPI to TS conversion - it takes a
80
+ * schema and returns the appropriate type.
81
+ */
82
+ __privateAdd(this, _getBaseTypeFromSchema);
83
+ this.refs = {};
84
+ this.extraNodes = [];
85
+ this.aliases = [];
86
+ // Keep track of already used type aliases
87
+ __privateAdd(this, _usedAliasNames, {});
88
+ __privateAdd(this, _caseOptions, {
89
+ delimiter: "",
90
+ stripRegexp: /[^A-Z0-9$]/gi
91
+ });
92
+ return this;
93
+ }
94
+ build({
95
+ schema,
96
+ baseName,
97
+ description,
98
+ keysToOmit
99
+ }) {
100
+ const nodes = [];
101
+ const type = __privateMethod(this, _getTypeFromSchema, getTypeFromSchema_fn).call(this, schema, baseName);
102
+ if (!type) {
103
+ return this.extraNodes;
104
+ }
105
+ const node = factory__namespace.createTypeAliasDeclaration({
106
+ modifiers: [factory__namespace.modifiers.export],
107
+ name: this.options.resolveName({ name: baseName }) || baseName,
108
+ type: keysToOmit?.length ? factory__namespace.createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : type
109
+ });
110
+ if (description) {
111
+ nodes.push(
112
+ factory__namespace.appendJSDocToNode({
113
+ node,
114
+ comments: [`@description ${description}`]
115
+ })
116
+ );
117
+ } else {
118
+ nodes.push(node);
119
+ }
120
+ const filterdNodes = nodes.filter(
121
+ (node2) => !this.extraNodes.some(
122
+ (extraNode) => extraNode?.name?.escapedText === node2?.name?.escapedText
123
+ )
124
+ );
125
+ return [...this.extraNodes, ...filterdNodes];
126
+ }
127
+ };
128
+ _usedAliasNames = new WeakMap();
129
+ _caseOptions = new WeakMap();
130
+ _getTypeFromSchema = new WeakSet();
131
+ getTypeFromSchema_fn = function(schema, name) {
132
+ const type = __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, schema, name);
133
+ if (!type) {
134
+ return null;
135
+ }
136
+ if (schema && !schema.nullable) {
137
+ return type;
138
+ }
139
+ return factory__namespace.createUnionDeclaration({ nodes: [type, factory__namespace.keywordTypeNodes.null] });
140
+ };
141
+ _getTypeFromProperties = new WeakSet();
142
+ getTypeFromProperties_fn = function(baseSchema, baseName) {
143
+ const { optionalType } = this.options;
144
+ const properties = baseSchema?.properties || {};
145
+ const required = baseSchema?.required;
146
+ const additionalProperties = baseSchema?.additionalProperties;
147
+ const members = Object.keys(properties).map((name) => {
148
+ const schema = properties[name];
149
+ const isRequired = required && required.includes(name);
150
+ let type = __privateMethod(this, _getTypeFromSchema, getTypeFromSchema_fn).call(this, schema, this.options.resolveName({ name: `${baseName || ""} ${name}` }));
151
+ if (!type) {
152
+ return null;
153
+ }
154
+ if (!isRequired && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
155
+ type = factory__namespace.createUnionDeclaration({ nodes: [type, factory__namespace.keywordTypeNodes.undefined] });
156
+ }
157
+ const propertySignature = factory__namespace.createPropertySignature({
158
+ questionToken: ["questionToken", "questionTokenAndUndefined"].includes(optionalType) && !isRequired,
159
+ name,
160
+ type,
161
+ readOnly: schema.readOnly
162
+ });
163
+ if (this.options.withJSDocs) {
164
+ return factory__namespace.appendJSDocToNode({
165
+ node: propertySignature,
166
+ comments: [
167
+ schema.description ? `@description ${schema.description}` : void 0,
168
+ schema.type ? `@type ${schema.type}${isRequired ? "" : " | undefined"} ${schema.format || ""}` : void 0,
169
+ schema.example ? `@example ${schema.example}` : void 0,
170
+ schema.deprecated ? `@deprecated` : void 0,
171
+ schema.default !== void 0 && typeof schema.default === "string" ? `@default '${schema.default}'` : void 0,
172
+ schema.default !== void 0 && typeof schema.default !== "string" ? `@default ${schema.default}` : void 0
173
+ ].filter(Boolean)
174
+ });
175
+ }
176
+ return propertySignature;
177
+ });
178
+ if (additionalProperties) {
179
+ const type = additionalProperties === true ? factory__namespace.keywordTypeNodes.any : __privateMethod(this, _getTypeFromSchema, getTypeFromSchema_fn).call(this, additionalProperties);
180
+ if (type) {
181
+ members.push(factory__namespace.createIndexSignature(type));
182
+ }
183
+ }
184
+ return factory__namespace.createTypeLiteralNode(members.filter(Boolean));
185
+ };
186
+ _getRefAlias = new WeakSet();
187
+ getRefAlias_fn = function(obj, _baseName) {
188
+ const { $ref } = obj;
189
+ let ref = this.refs[$ref];
190
+ if (ref) {
191
+ return factory__namespace.createTypeReferenceNode(ref.propertyName, void 0);
192
+ }
193
+ const originalName = utils.getUniqueName($ref.replace(/.+\//, ""), __privateGet(this, _usedAliasNames));
194
+ const propertyName = this.options.resolveName({ name: originalName }) || originalName;
195
+ ref = this.refs[$ref] = {
196
+ propertyName,
197
+ originalName
198
+ };
199
+ return factory__namespace.createTypeReferenceNode(ref.propertyName, void 0);
200
+ };
201
+ _getBaseTypeFromSchema = new WeakSet();
202
+ getBaseTypeFromSchema_fn = function(schema, baseName) {
203
+ if (!schema) {
204
+ return factory__namespace.keywordTypeNodes.any;
205
+ }
206
+ if (utils$1.isReference(schema)) {
207
+ return __privateMethod(this, _getRefAlias, getRefAlias_fn).call(this, schema, baseName);
208
+ }
209
+ if (schema.oneOf) {
210
+ const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
211
+ const union = factory__namespace.createUnionDeclaration({
212
+ withParentheses: true,
213
+ nodes: schema.oneOf.map((item) => {
214
+ return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
215
+ }).filter((item) => {
216
+ return item && item !== factory__namespace.keywordTypeNodes.any;
217
+ })
218
+ });
219
+ if (schemaWithoutOneOf.properties) {
220
+ return factory__namespace.createIntersectionDeclaration({
221
+ nodes: [__privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, schemaWithoutOneOf, baseName), union].filter(Boolean)
222
+ });
223
+ }
224
+ return union;
225
+ }
226
+ if (schema.anyOf) {
227
+ const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
228
+ const union = factory__namespace.createUnionDeclaration({
229
+ withParentheses: true,
230
+ nodes: schema.anyOf.map((item) => {
231
+ return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
232
+ }).filter((item) => {
233
+ return item && item !== factory__namespace.keywordTypeNodes.any;
234
+ })
235
+ });
236
+ if (schemaWithoutAnyOf.properties) {
237
+ return factory__namespace.createIntersectionDeclaration({
238
+ nodes: [__privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, schemaWithoutAnyOf, baseName), union].filter(Boolean)
239
+ });
240
+ }
241
+ return union;
242
+ }
243
+ if (schema.allOf) {
244
+ const schemaWithoutAllOf = { ...schema, allOf: void 0 };
245
+ const and = factory__namespace.createIntersectionDeclaration({
246
+ withParentheses: true,
247
+ nodes: schema.allOf.map((item) => {
248
+ return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item);
249
+ }).filter((item) => {
250
+ return item && item !== factory__namespace.keywordTypeNodes.any;
251
+ })
252
+ });
253
+ if (schemaWithoutAllOf.properties) {
254
+ return factory__namespace.createIntersectionDeclaration({
255
+ nodes: [__privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, schemaWithoutAllOf, baseName), and].filter(Boolean)
256
+ });
257
+ }
258
+ return and;
259
+ }
260
+ if (schema.enum && baseName) {
261
+ const enumName = utils.getUniqueName(baseName, this.options.usedEnumNames);
262
+ let enums = [...new Set(schema.enum)].map((key) => [key, key]);
263
+ if ("x-enumNames" in schema) {
264
+ enums = [...new Set(schema["x-enumNames"])].map((key, index) => {
265
+ return [key, schema.enum?.[index]];
266
+ });
267
+ }
268
+ this.extraNodes.push(
269
+ ...factory__namespace.createEnumDeclaration({
270
+ name: changeCase.camelCase(enumName, __privateGet(this, _caseOptions)),
271
+ typeName: this.options.resolveName({ name: enumName }),
272
+ enums,
273
+ type: this.options.enumType
274
+ })
275
+ );
276
+ return factory__namespace.createTypeReferenceNode(this.options.resolveName({ name: enumName }), void 0);
277
+ }
278
+ if (schema.enum) {
279
+ return factory__namespace.createUnionDeclaration({
280
+ nodes: schema.enum.map((name) => {
281
+ return factory__namespace.createLiteralTypeNode(typeof name === "number" ? factory__namespace.createNumericLiteral(name) : factory__namespace.createStringLiteral(`${name}`));
282
+ })
283
+ });
284
+ }
285
+ if ("items" in schema) {
286
+ const node = __privateMethod(this, _getTypeFromSchema, getTypeFromSchema_fn).call(this, schema.items, baseName);
287
+ if (node) {
288
+ return factory__namespace.createArrayTypeNode(node);
289
+ }
290
+ }
291
+ if ("prefixItems" in schema) {
292
+ const prefixItems = schema.prefixItems;
293
+ return factory__namespace.createTupleDeclaration({
294
+ nodes: prefixItems.map((item) => {
295
+ return __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, item, void 0);
296
+ })
297
+ });
298
+ }
299
+ if (schema.properties || schema.additionalProperties) {
300
+ return __privateMethod(this, _getTypeFromProperties, getTypeFromProperties_fn).call(this, schema, baseName);
301
+ }
302
+ if (schema.type) {
303
+ if (Array.isArray(schema.type)) {
304
+ const [type, nullable] = schema.type;
305
+ return factory__namespace.createUnionDeclaration({
306
+ nodes: [
307
+ __privateMethod(this, _getBaseTypeFromSchema, getBaseTypeFromSchema_fn).call(this, {
308
+ ...schema,
309
+ type
310
+ }, baseName),
311
+ nullable ? factory__namespace.createLiteralTypeNode(factory__namespace.createNull()) : void 0
312
+ ].filter(Boolean)
313
+ });
314
+ }
315
+ if (this.options.dateType === "date" && ["date", "date-time"].some((item) => item === schema.format)) {
316
+ return factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier("Date"));
317
+ }
318
+ if (schema.type in factory__namespace.keywordTypeNodes) {
319
+ return factory__namespace.keywordTypeNodes[schema.type];
320
+ }
321
+ }
322
+ if (schema.format === "binary") {
323
+ return factory__namespace.createTypeReferenceNode("Blob", []);
324
+ }
325
+ return factory__namespace.keywordTypeNodes.any;
326
+ };
327
+
328
+ // src/builders/TypeBuilder.ts
329
+ var TypeBuilder = class extends swagger.OasBuilder {
330
+ configure(options) {
331
+ if (options) {
332
+ this.options = options;
333
+ }
334
+ if (this.options.fileResolver) {
335
+ this.options.withImports = true;
336
+ }
337
+ return this;
338
+ }
339
+ print(name) {
340
+ const codes = [];
341
+ const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(utils.transformers.nameSorter).map((operationSchema) => {
342
+ const generator = new TypeGenerator({
343
+ usedEnumNames: this.options.usedEnumNames,
344
+ withJSDocs: this.options.withJSDocs,
345
+ resolveName: this.options.resolveName,
346
+ enumType: this.options.enumType,
347
+ dateType: this.options.dateType,
348
+ optionalType: this.options.optionalType
349
+ });
350
+ const sources = generator.build({
351
+ schema: operationSchema.schema,
352
+ baseName: operationSchema.name,
353
+ description: operationSchema.description,
354
+ keysToOmit: operationSchema.keysToOmit
355
+ });
356
+ return {
357
+ import: {
358
+ refs: generator.refs,
359
+ name: operationSchema.name
360
+ },
361
+ sources
362
+ };
363
+ }).sort(utils$1.refsSorter);
364
+ generated.forEach((item) => {
365
+ codes.push(parser.print(item.sources));
366
+ });
367
+ if (this.options.withImports) {
368
+ const importsGenerator = new swagger.ImportsGenerator({ fileResolver: this.options.fileResolver });
369
+ const importMeta = importsGenerator.build(generated.map((item) => item.import));
370
+ if (importMeta) {
371
+ const nodes = importMeta.map((item) => {
372
+ return factory__namespace.createImportDeclaration({
373
+ name: [{ propertyName: item.ref.propertyName }],
374
+ path: item.path,
375
+ isTypeOnly: true
376
+ });
377
+ });
378
+ codes.unshift(parser.print(nodes));
379
+ }
380
+ }
381
+ return utils.transformers.combineCodes(codes);
382
+ }
383
+ };
384
+ var OperationGenerator = class extends swagger.OperationGenerator {
385
+ resolve(operation) {
386
+ const { pluginManager, plugin } = this.context;
387
+ return swagger.resolve({
388
+ operation,
389
+ resolveName: pluginManager.resolveName,
390
+ resolvePath: pluginManager.resolvePath,
391
+ pluginKey: plugin?.key
392
+ });
393
+ }
394
+ async all() {
395
+ return null;
396
+ }
397
+ async get(operation, schemas, options) {
398
+ const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
399
+ const { pluginManager, plugin } = this.context;
400
+ const type = this.resolve(operation);
401
+ const fileResolver = (name) => {
402
+ const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
403
+ const resolvedTypeId = pluginManager.resolvePath({
404
+ baseName: `${name}.ts`,
405
+ pluginKey: plugin?.key
406
+ });
407
+ return utils.getRelativePath(root, resolvedTypeId);
408
+ };
409
+ const source = new TypeBuilder({
410
+ usedEnumNames,
411
+ fileResolver: mode === "file" ? void 0 : fileResolver,
412
+ withJSDocs: true,
413
+ resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
414
+ enumType,
415
+ optionalType,
416
+ dateType
417
+ }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.errors).configure().print();
418
+ return {
419
+ path: type.path,
420
+ baseName: type.baseName,
421
+ source,
422
+ meta: {
423
+ pluginKey: plugin.key,
424
+ tag: operation.getTags()[0]?.name
425
+ }
426
+ };
427
+ }
428
+ async post(operation, schemas, options) {
429
+ const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
430
+ const { pluginManager, plugin } = this.context;
431
+ const type = this.resolve(operation);
432
+ const fileResolver = (name) => {
433
+ const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
434
+ const resolvedTypeId = pluginManager.resolvePath({
435
+ baseName: `${name}.ts`,
436
+ pluginKey: plugin?.key
437
+ });
438
+ return utils.getRelativePath(root, resolvedTypeId);
439
+ };
440
+ const source = new TypeBuilder({
441
+ usedEnumNames,
442
+ fileResolver: mode === "file" ? void 0 : fileResolver,
443
+ withJSDocs: true,
444
+ resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
445
+ enumType,
446
+ optionalType,
447
+ dateType
448
+ }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure().print();
449
+ return {
450
+ path: type.path,
451
+ baseName: type.baseName,
452
+ source,
453
+ meta: {
454
+ pluginKey: plugin.key,
455
+ tag: operation.getTags()[0]?.name
456
+ }
457
+ };
458
+ }
459
+ async put(operation, schemas, options) {
460
+ return this.post(operation, schemas, options);
461
+ }
462
+ async patch(operation, schemas, options) {
463
+ return this.post(operation, schemas, options);
464
+ }
465
+ async delete(operation, schemas, options) {
466
+ return this.post(operation, schemas, options);
467
+ }
468
+ };
469
+
470
+ // src/plugin.ts
471
+ var pluginName = "swagger-ts";
472
+ var pluginKey = ["schema", pluginName];
473
+ core.createPlugin((options) => {
474
+ const {
475
+ output = "types",
476
+ groupBy,
477
+ skipBy = [],
478
+ overrideBy = [],
479
+ enumType = "asConst",
480
+ dateType = "string",
481
+ optionalType = "questionToken",
482
+ transformers: transformers2 = {},
483
+ exportAs
484
+ } = options;
485
+ const template = groupBy?.output ? groupBy.output : `${output}/{{tag}}Controller`;
486
+ let pluginsOptions;
487
+ return {
488
+ name: pluginName,
489
+ options,
490
+ kind: "schema",
491
+ validate(plugins) {
492
+ pluginsOptions = core.PluginManager.getDependedPlugins(plugins, [swagger.pluginName]);
493
+ return true;
494
+ },
495
+ resolvePath(baseName, directory, options2) {
496
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
497
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output));
498
+ if (mode === "file") {
499
+ return path__default.default.resolve(root, output);
500
+ }
501
+ if (options2?.tag && groupBy?.type === "tag") {
502
+ const tag = changeCase.camelCase(options2.tag, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
503
+ return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
504
+ }
505
+ return path__default.default.resolve(root, output, baseName);
506
+ },
507
+ resolveName(name) {
508
+ const resolvedName = changeCase.pascalCase(name, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: changeCase.pascalCaseTransformMerge });
509
+ return transformers2?.name?.(resolvedName) || resolvedName;
510
+ },
511
+ async writeFile(source, writePath) {
512
+ if (!writePath.endsWith(".ts") || !source) {
513
+ return;
514
+ }
515
+ return this.fileManager.write(source, writePath);
516
+ },
517
+ async buildStart() {
518
+ const [swaggerPlugin] = pluginsOptions;
519
+ const oas = await swaggerPlugin.api.getOas();
520
+ const schemas = await swaggerPlugin.api.getSchemas();
521
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
522
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output));
523
+ const usedEnumNames = {};
524
+ if (mode === "directory") {
525
+ const builder = await new TypeBuilder({
526
+ usedEnumNames,
527
+ resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),
528
+ fileResolver: (name) => {
529
+ const resolvedTypeId = this.resolvePath({
530
+ baseName: `${name}.ts`,
531
+ pluginKey: this.plugin.key
532
+ });
533
+ const root2 = this.resolvePath({ baseName: ``, pluginKey: this.plugin.key });
534
+ return utils.getRelativePath(root2, resolvedTypeId);
535
+ },
536
+ withJSDocs: true,
537
+ enumType,
538
+ dateType,
539
+ optionalType
540
+ }).configure();
541
+ Object.entries(schemas).forEach(([name, schema]) => {
542
+ return builder.add({
543
+ schema,
544
+ name
545
+ });
546
+ });
547
+ const mapFolderSchema = async ([name]) => {
548
+ const resolvedPath = this.resolvePath({ baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`, pluginKey: this.plugin.key });
549
+ if (!resolvedPath) {
550
+ return null;
551
+ }
552
+ return this.addFile({
553
+ path: resolvedPath,
554
+ baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`,
555
+ source: builder.print(name),
556
+ meta: {
557
+ pluginKey: this.plugin.key
558
+ }
559
+ });
560
+ };
561
+ const promises = Object.entries(schemas).map(mapFolderSchema);
562
+ await Promise.all(promises);
563
+ }
564
+ if (mode === "file") {
565
+ const builder = new TypeBuilder({
566
+ usedEnumNames,
567
+ resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),
568
+ withJSDocs: true,
569
+ enumType,
570
+ dateType,
571
+ optionalType
572
+ }).configure();
573
+ Object.entries(schemas).forEach(([name, schema]) => {
574
+ return builder.add({
575
+ schema,
576
+ name
577
+ });
578
+ });
579
+ const resolvedPath = this.resolvePath({ baseName: "", pluginKey: this.plugin.key });
580
+ if (!resolvedPath) {
581
+ return;
582
+ }
583
+ await this.addFile({
584
+ path: resolvedPath,
585
+ baseName: output,
586
+ source: builder.print(),
587
+ meta: {
588
+ pluginKey: this.plugin.key
589
+ },
590
+ validate: false
591
+ });
592
+ }
593
+ const operationGenerator = new OperationGenerator(
594
+ {
595
+ mode,
596
+ enumType,
597
+ dateType,
598
+ optionalType,
599
+ usedEnumNames
600
+ },
601
+ {
602
+ oas,
603
+ pluginManager: this.pluginManager,
604
+ plugin: this.plugin,
605
+ contentType: swaggerPlugin.api.contentType,
606
+ skipBy,
607
+ overrideBy
608
+ }
609
+ );
610
+ const files = await operationGenerator.build();
611
+ await this.addFile(...files);
612
+ },
613
+ async buildEnd() {
614
+ if (this.config.output.write === false) {
615
+ return;
616
+ }
617
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
618
+ await this.fileManager.addIndexes({
619
+ root,
620
+ extName: ".ts",
621
+ meta: { pluginKey: this.plugin.key },
622
+ options: {
623
+ map: (file) => {
624
+ return {
625
+ ...file,
626
+ exports: file.exports?.map((item) => {
627
+ if (exportAs) {
628
+ return {
629
+ ...item,
630
+ name: exportAs,
631
+ asAlias: !!exportAs
632
+ };
633
+ }
634
+ return item;
635
+ })
636
+ };
637
+ },
638
+ output,
639
+ isTypeOnly: true
640
+ }
641
+ });
642
+ }
643
+ };
644
+ });
645
+
646
+ // src/hooks/useResolve.ts
647
+ function useResolve(props = {}) {
648
+ return hooks.useResolve({ pluginKey, ...props });
649
+ }
650
+
651
+ exports.useResolve = useResolve;
652
+ //# sourceMappingURL=out.js.map
653
+ //# sourceMappingURL=hooks.cjs.map