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