@kubb/swagger-ts 2.0.0-canary.20231030T125204 → 2.0.1

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