@kubb/swagger-ts 2.0.0-alpha.1 → 2.0.0-alpha.11

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 DELETED
@@ -1,656 +0,0 @@
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
- if ("const" in schema && schema["const"] !== void 0 && typeof schema["const"] === "string") {
326
- return factory__namespace.createLiteralTypeNode(factory__namespace.createStringLiteral(schema["const"]));
327
- }
328
- return factory__namespace.keywordTypeNodes.any;
329
- };
330
-
331
- // src/builders/TypeBuilder.ts
332
- var TypeBuilder = class extends swagger.OasBuilder {
333
- configure(options) {
334
- if (options) {
335
- this.options = options;
336
- }
337
- if (this.options.fileResolver) {
338
- this.options.withImports = true;
339
- }
340
- return this;
341
- }
342
- print(name) {
343
- const codes = [];
344
- const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(utils.transformers.nameSorter).map((operationSchema) => {
345
- const generator = new TypeGenerator({
346
- usedEnumNames: this.options.usedEnumNames,
347
- withJSDocs: this.options.withJSDocs,
348
- resolveName: this.options.resolveName,
349
- enumType: this.options.enumType,
350
- dateType: this.options.dateType,
351
- optionalType: this.options.optionalType
352
- });
353
- const sources = generator.build({
354
- schema: operationSchema.schema,
355
- baseName: operationSchema.name,
356
- description: operationSchema.description,
357
- keysToOmit: operationSchema.keysToOmit
358
- });
359
- return {
360
- import: {
361
- refs: generator.refs,
362
- name: operationSchema.name
363
- },
364
- sources
365
- };
366
- }).sort(utils$1.refsSorter);
367
- generated.forEach((item) => {
368
- codes.push(parser.print(item.sources));
369
- });
370
- if (this.options.withImports) {
371
- const importsGenerator = new swagger.ImportsGenerator({ fileResolver: this.options.fileResolver });
372
- const importMeta = importsGenerator.build(generated.map((item) => item.import));
373
- if (importMeta) {
374
- const nodes = importMeta.map((item) => {
375
- return factory__namespace.createImportDeclaration({
376
- name: [{ propertyName: item.ref.propertyName }],
377
- path: item.path,
378
- isTypeOnly: true
379
- });
380
- });
381
- codes.unshift(parser.print(nodes));
382
- }
383
- }
384
- return utils.transformers.combineCodes(codes);
385
- }
386
- };
387
- var OperationGenerator = class extends swagger.OperationGenerator {
388
- resolve(operation) {
389
- const { pluginManager, plugin } = this.context;
390
- return swagger.resolve({
391
- operation,
392
- resolveName: pluginManager.resolveName,
393
- resolvePath: pluginManager.resolvePath,
394
- pluginKey: plugin?.key
395
- });
396
- }
397
- async all() {
398
- return null;
399
- }
400
- async get(operation, schemas, options) {
401
- const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
402
- const { pluginManager, plugin } = this.context;
403
- const type = this.resolve(operation);
404
- const fileResolver = (name) => {
405
- const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
406
- const resolvedTypeId = pluginManager.resolvePath({
407
- baseName: `${name}.ts`,
408
- pluginKey: plugin?.key
409
- });
410
- return utils.getRelativePath(root, resolvedTypeId);
411
- };
412
- const source = new TypeBuilder({
413
- usedEnumNames,
414
- fileResolver: mode === "file" ? void 0 : fileResolver,
415
- withJSDocs: true,
416
- resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
417
- enumType,
418
- optionalType,
419
- dateType
420
- }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.response).add(schemas.errors).configure().print();
421
- return {
422
- path: type.path,
423
- baseName: type.baseName,
424
- source,
425
- meta: {
426
- pluginKey: plugin.key,
427
- tag: operation.getTags()[0]?.name
428
- }
429
- };
430
- }
431
- async post(operation, schemas, options) {
432
- const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
433
- const { pluginManager, plugin } = this.context;
434
- const type = this.resolve(operation);
435
- const fileResolver = (name) => {
436
- const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
437
- const resolvedTypeId = pluginManager.resolvePath({
438
- baseName: `${name}.ts`,
439
- pluginKey: plugin?.key
440
- });
441
- return utils.getRelativePath(root, resolvedTypeId);
442
- };
443
- const source = new TypeBuilder({
444
- usedEnumNames,
445
- fileResolver: mode === "file" ? void 0 : fileResolver,
446
- withJSDocs: true,
447
- resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
448
- enumType,
449
- optionalType,
450
- dateType
451
- }).add(schemas.pathParams).add(schemas.queryParams).add(schemas.headerParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure().print();
452
- return {
453
- path: type.path,
454
- baseName: type.baseName,
455
- source,
456
- meta: {
457
- pluginKey: plugin.key,
458
- tag: operation.getTags()[0]?.name
459
- }
460
- };
461
- }
462
- async put(operation, schemas, options) {
463
- return this.post(operation, schemas, options);
464
- }
465
- async patch(operation, schemas, options) {
466
- return this.post(operation, schemas, options);
467
- }
468
- async delete(operation, schemas, options) {
469
- return this.post(operation, schemas, options);
470
- }
471
- };
472
-
473
- // src/plugin.ts
474
- var pluginName = "swagger-ts";
475
- var pluginKey = ["schema", pluginName];
476
- core.createPlugin((options) => {
477
- const {
478
- output = "types",
479
- groupBy,
480
- skipBy = [],
481
- overrideBy = [],
482
- enumType = "asConst",
483
- dateType = "string",
484
- optionalType = "questionToken",
485
- transformers: transformers2 = {},
486
- exportAs
487
- } = options;
488
- const template = groupBy?.output ? groupBy.output : `${output}/{{tag}}Controller`;
489
- let pluginsOptions;
490
- return {
491
- name: pluginName,
492
- options,
493
- kind: "schema",
494
- validate(plugins) {
495
- pluginsOptions = core.PluginManager.getDependedPlugins(plugins, [swagger.pluginName]);
496
- return true;
497
- },
498
- resolvePath(baseName, directory, options2) {
499
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
500
- const mode = core.FileManager.getMode(path__default.default.resolve(root, output));
501
- if (mode === "file") {
502
- return path__default.default.resolve(root, output);
503
- }
504
- if (options2?.tag && groupBy?.type === "tag") {
505
- const tag = changeCase.camelCase(options2.tag, { delimiter: "", transform: changeCase.camelCaseTransformMerge });
506
- return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
507
- }
508
- return path__default.default.resolve(root, output, baseName);
509
- },
510
- resolveName(name) {
511
- const resolvedName = changeCase.pascalCase(name, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: changeCase.pascalCaseTransformMerge });
512
- return transformers2?.name?.(resolvedName) || resolvedName;
513
- },
514
- async writeFile(source, writePath) {
515
- if (!writePath.endsWith(".ts") || !source) {
516
- return;
517
- }
518
- return this.fileManager.write(source, writePath);
519
- },
520
- async buildStart() {
521
- const [swaggerPlugin] = pluginsOptions;
522
- const oas = await swaggerPlugin.api.getOas();
523
- const schemas = await swaggerPlugin.api.getSchemas();
524
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
525
- const mode = core.FileManager.getMode(path__default.default.resolve(root, output));
526
- const usedEnumNames = {};
527
- if (mode === "directory") {
528
- const builder = await new TypeBuilder({
529
- usedEnumNames,
530
- resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),
531
- fileResolver: (name) => {
532
- const resolvedTypeId = this.resolvePath({
533
- baseName: `${name}.ts`,
534
- pluginKey: this.plugin.key
535
- });
536
- const root2 = this.resolvePath({ baseName: ``, pluginKey: this.plugin.key });
537
- return utils.getRelativePath(root2, resolvedTypeId);
538
- },
539
- withJSDocs: true,
540
- enumType,
541
- dateType,
542
- optionalType
543
- }).configure();
544
- Object.entries(schemas).forEach(([name, schema]) => {
545
- return builder.add({
546
- schema,
547
- name
548
- });
549
- });
550
- const mapFolderSchema = async ([name]) => {
551
- const resolvedPath = this.resolvePath({ baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`, pluginKey: this.plugin.key });
552
- if (!resolvedPath) {
553
- return null;
554
- }
555
- return this.addFile({
556
- path: resolvedPath,
557
- baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`,
558
- source: builder.print(name),
559
- meta: {
560
- pluginKey: this.plugin.key
561
- }
562
- });
563
- };
564
- const promises = Object.entries(schemas).map(mapFolderSchema);
565
- await Promise.all(promises);
566
- }
567
- if (mode === "file") {
568
- const builder = new TypeBuilder({
569
- usedEnumNames,
570
- resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),
571
- withJSDocs: true,
572
- enumType,
573
- dateType,
574
- optionalType
575
- }).configure();
576
- Object.entries(schemas).forEach(([name, schema]) => {
577
- return builder.add({
578
- schema,
579
- name
580
- });
581
- });
582
- const resolvedPath = this.resolvePath({ baseName: "", pluginKey: this.plugin.key });
583
- if (!resolvedPath) {
584
- return;
585
- }
586
- await this.addFile({
587
- path: resolvedPath,
588
- baseName: output,
589
- source: builder.print(),
590
- meta: {
591
- pluginKey: this.plugin.key
592
- },
593
- validate: false
594
- });
595
- }
596
- const operationGenerator = new OperationGenerator(
597
- {
598
- mode,
599
- enumType,
600
- dateType,
601
- optionalType,
602
- usedEnumNames
603
- },
604
- {
605
- oas,
606
- pluginManager: this.pluginManager,
607
- plugin: this.plugin,
608
- contentType: swaggerPlugin.api.contentType,
609
- skipBy,
610
- overrideBy
611
- }
612
- );
613
- const files = await operationGenerator.build();
614
- await this.addFile(...files);
615
- },
616
- async buildEnd() {
617
- if (this.config.output.write === false) {
618
- return;
619
- }
620
- const root = path__default.default.resolve(this.config.root, this.config.output.path);
621
- await this.fileManager.addIndexes({
622
- root,
623
- extName: ".ts",
624
- meta: { pluginKey: this.plugin.key },
625
- options: {
626
- map: (file) => {
627
- return {
628
- ...file,
629
- exports: file.exports?.map((item) => {
630
- if (exportAs) {
631
- return {
632
- ...item,
633
- name: exportAs,
634
- asAlias: !!exportAs
635
- };
636
- }
637
- return item;
638
- })
639
- };
640
- },
641
- output,
642
- isTypeOnly: true
643
- }
644
- });
645
- }
646
- };
647
- });
648
-
649
- // src/hooks/useResolve.ts
650
- function useResolve(props = {}) {
651
- return hooks.useResolve({ pluginKey, ...props });
652
- }
653
-
654
- exports.useResolve = useResolve;
655
- //# sourceMappingURL=out.js.map
656
- //# sourceMappingURL=hooks.cjs.map