@kubb/swagger-ts 1.15.0-canary.20231023T125947 → 1.15.0-canary.20231024T104451
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/index.cjs +103 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -17
- package/dist/index.d.ts +20 -17
- package/dist/index.js +103 -77
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
2
|
-
import { PluginFactoryOptions, PluginContext, KubbFile, SchemaGenerator } from '@kubb/core';
|
2
|
+
import { KubbPlugin, PluginFactoryOptions, PluginContext, KubbFile, SchemaGenerator } from '@kubb/core';
|
3
3
|
import { SkipBy, OverrideBy, ResolvePathOptions, OasBuilder, FileResolver, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OpenAPIV3, Refs, UseResolveProps, ResolveProps } from '@kubb/swagger';
|
4
4
|
import ts from 'typescript';
|
5
|
-
import { Options as Options$4 } from 'change-case';
|
6
5
|
|
7
6
|
type Options$3 = {
|
8
7
|
/**
|
@@ -28,6 +27,10 @@ type Options$3 = {
|
|
28
27
|
*/
|
29
28
|
output?: string;
|
30
29
|
};
|
30
|
+
/**
|
31
|
+
* Name to be used for the `export * as {{exportAs}} from './`
|
32
|
+
*/
|
33
|
+
exportAs?: string;
|
31
34
|
/**
|
32
35
|
* Array containing skipBy paramaters to exclude/skip tags/operations/methods/paths.
|
33
36
|
*/
|
@@ -62,15 +65,22 @@ type Options$3 = {
|
|
62
65
|
};
|
63
66
|
};
|
64
67
|
type FileMeta = {
|
65
|
-
|
68
|
+
pluginKey?: KubbPlugin['key'];
|
66
69
|
tag?: string;
|
67
70
|
};
|
68
|
-
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$3, false, never, ResolvePathOptions>;
|
71
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', 'schema', Options$3, false, never, ResolvePathOptions>;
|
72
|
+
declare module '@kubb/core' {
|
73
|
+
interface _Register {
|
74
|
+
['@kubb/swagger-ts']: PluginOptions;
|
75
|
+
}
|
76
|
+
}
|
69
77
|
|
70
|
-
declare const pluginName
|
78
|
+
declare const pluginName = "swagger-ts";
|
79
|
+
declare const pluginKey: PluginOptions['key'];
|
71
80
|
declare const definePlugin: (options: Options$3) => _kubb_core.KubbUserPlugin<PluginOptions>;
|
72
81
|
|
73
82
|
type Options$2 = {
|
83
|
+
usedEnumNames: Record<string, number>;
|
74
84
|
resolveName: PluginContext['resolveName'];
|
75
85
|
fileResolver?: FileResolver;
|
76
86
|
withJSDocs?: boolean;
|
@@ -85,6 +95,7 @@ declare class TypeBuilder extends OasBuilder<Options$2, never> {
|
|
85
95
|
}
|
86
96
|
|
87
97
|
type Options$1 = {
|
98
|
+
usedEnumNames: Record<string, number>;
|
88
99
|
mode: KubbFile.Mode;
|
89
100
|
enumType: NonNullable<Options$3['enumType']>;
|
90
101
|
dateType: NonNullable<Options$3['dateType']>;
|
@@ -101,6 +112,7 @@ declare class OperationGenerator extends OperationGenerator$1<Options$1> {
|
|
101
112
|
}
|
102
113
|
|
103
114
|
type Options = {
|
115
|
+
usedEnumNames: Record<string, number>;
|
104
116
|
withJSDocs?: boolean;
|
105
117
|
resolveName: PluginContext['resolveName'];
|
106
118
|
enumType: 'enum' | 'asConst' | 'asPascalConst';
|
@@ -109,12 +121,9 @@ type Options = {
|
|
109
121
|
};
|
110
122
|
declare class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {
|
111
123
|
#private;
|
112
|
-
static usedEnumNames: Record<string, number>;
|
113
124
|
refs: Refs;
|
114
125
|
extraNodes: ts.Node[];
|
115
126
|
aliases: ts.TypeAliasDeclaration[];
|
116
|
-
usedAliasNames: Record<string, number>;
|
117
|
-
caseOptions: Options$4;
|
118
127
|
constructor(options?: Options);
|
119
128
|
build({ schema, baseName, description, keysToOmit, }: {
|
120
129
|
schema: OpenAPIV3.SchemaObject;
|
@@ -124,10 +133,7 @@ declare class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObj
|
|
124
133
|
}): ts.Node[];
|
125
134
|
}
|
126
135
|
|
127
|
-
|
128
|
-
pluginName?: never;
|
129
|
-
};
|
130
|
-
declare function useResolve(props?: Props$1): Resolver;
|
136
|
+
declare function useResolve(props?: UseResolveProps): Resolver;
|
131
137
|
|
132
138
|
declare const keywordTypeNodes: {
|
133
139
|
readonly any: ts.KeywordTypeNode<ts.SyntaxKind.AnyKeyword>;
|
@@ -140,9 +146,6 @@ declare const keywordTypeNodes: {
|
|
140
146
|
readonly null: ts.LiteralTypeNode;
|
141
147
|
};
|
142
148
|
|
143
|
-
|
144
|
-
pluginName?: never;
|
145
|
-
};
|
146
|
-
declare function resolve(props: Props): Resolver;
|
149
|
+
declare function resolve(props: ResolveProps): Resolver;
|
147
150
|
|
148
|
-
export { FileMeta, OperationGenerator, Options$3 as Options, PluginOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName, resolve, useResolve };
|
151
|
+
export { FileMeta, OperationGenerator, Options$3 as Options, PluginOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginKey, pluginName, resolve, useResolve };
|
package/dist/index.d.ts
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
2
|
-
import { PluginFactoryOptions, PluginContext, KubbFile, SchemaGenerator } from '@kubb/core';
|
2
|
+
import { KubbPlugin, PluginFactoryOptions, PluginContext, KubbFile, SchemaGenerator } from '@kubb/core';
|
3
3
|
import { SkipBy, OverrideBy, ResolvePathOptions, OasBuilder, FileResolver, OperationGenerator as OperationGenerator$1, Operation, Resolver, OperationSchemas, OpenAPIV3, Refs, UseResolveProps, ResolveProps } from '@kubb/swagger';
|
4
4
|
import ts from 'typescript';
|
5
|
-
import { Options as Options$4 } from 'change-case';
|
6
5
|
|
7
6
|
type Options$3 = {
|
8
7
|
/**
|
@@ -28,6 +27,10 @@ type Options$3 = {
|
|
28
27
|
*/
|
29
28
|
output?: string;
|
30
29
|
};
|
30
|
+
/**
|
31
|
+
* Name to be used for the `export * as {{exportAs}} from './`
|
32
|
+
*/
|
33
|
+
exportAs?: string;
|
31
34
|
/**
|
32
35
|
* Array containing skipBy paramaters to exclude/skip tags/operations/methods/paths.
|
33
36
|
*/
|
@@ -62,15 +65,22 @@ type Options$3 = {
|
|
62
65
|
};
|
63
66
|
};
|
64
67
|
type FileMeta = {
|
65
|
-
|
68
|
+
pluginKey?: KubbPlugin['key'];
|
66
69
|
tag?: string;
|
67
70
|
};
|
68
|
-
type PluginOptions = PluginFactoryOptions<'swagger-ts', Options$3, false, never, ResolvePathOptions>;
|
71
|
+
type PluginOptions = PluginFactoryOptions<'swagger-ts', 'schema', Options$3, false, never, ResolvePathOptions>;
|
72
|
+
declare module '@kubb/core' {
|
73
|
+
interface _Register {
|
74
|
+
['@kubb/swagger-ts']: PluginOptions;
|
75
|
+
}
|
76
|
+
}
|
69
77
|
|
70
|
-
declare const pluginName
|
78
|
+
declare const pluginName = "swagger-ts";
|
79
|
+
declare const pluginKey: PluginOptions['key'];
|
71
80
|
declare const definePlugin: (options: Options$3) => _kubb_core.KubbUserPlugin<PluginOptions>;
|
72
81
|
|
73
82
|
type Options$2 = {
|
83
|
+
usedEnumNames: Record<string, number>;
|
74
84
|
resolveName: PluginContext['resolveName'];
|
75
85
|
fileResolver?: FileResolver;
|
76
86
|
withJSDocs?: boolean;
|
@@ -85,6 +95,7 @@ declare class TypeBuilder extends OasBuilder<Options$2, never> {
|
|
85
95
|
}
|
86
96
|
|
87
97
|
type Options$1 = {
|
98
|
+
usedEnumNames: Record<string, number>;
|
88
99
|
mode: KubbFile.Mode;
|
89
100
|
enumType: NonNullable<Options$3['enumType']>;
|
90
101
|
dateType: NonNullable<Options$3['dateType']>;
|
@@ -101,6 +112,7 @@ declare class OperationGenerator extends OperationGenerator$1<Options$1> {
|
|
101
112
|
}
|
102
113
|
|
103
114
|
type Options = {
|
115
|
+
usedEnumNames: Record<string, number>;
|
104
116
|
withJSDocs?: boolean;
|
105
117
|
resolveName: PluginContext['resolveName'];
|
106
118
|
enumType: 'enum' | 'asConst' | 'asPascalConst';
|
@@ -109,12 +121,9 @@ type Options = {
|
|
109
121
|
};
|
110
122
|
declare class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObject, ts.Node[]> {
|
111
123
|
#private;
|
112
|
-
static usedEnumNames: Record<string, number>;
|
113
124
|
refs: Refs;
|
114
125
|
extraNodes: ts.Node[];
|
115
126
|
aliases: ts.TypeAliasDeclaration[];
|
116
|
-
usedAliasNames: Record<string, number>;
|
117
|
-
caseOptions: Options$4;
|
118
127
|
constructor(options?: Options);
|
119
128
|
build({ schema, baseName, description, keysToOmit, }: {
|
120
129
|
schema: OpenAPIV3.SchemaObject;
|
@@ -124,10 +133,7 @@ declare class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObj
|
|
124
133
|
}): ts.Node[];
|
125
134
|
}
|
126
135
|
|
127
|
-
|
128
|
-
pluginName?: never;
|
129
|
-
};
|
130
|
-
declare function useResolve(props?: Props$1): Resolver;
|
136
|
+
declare function useResolve(props?: UseResolveProps): Resolver;
|
131
137
|
|
132
138
|
declare const keywordTypeNodes: {
|
133
139
|
readonly any: ts.KeywordTypeNode<ts.SyntaxKind.AnyKeyword>;
|
@@ -140,9 +146,6 @@ declare const keywordTypeNodes: {
|
|
140
146
|
readonly null: ts.LiteralTypeNode;
|
141
147
|
};
|
142
148
|
|
143
|
-
|
144
|
-
pluginName?: never;
|
145
|
-
};
|
146
|
-
declare function resolve(props: Props): Resolver;
|
149
|
+
declare function resolve(props: ResolveProps): Resolver;
|
147
150
|
|
148
|
-
export { FileMeta, OperationGenerator, Options$3 as Options, PluginOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginName, resolve, useResolve };
|
151
|
+
export { FileMeta, OperationGenerator, Options$3 as Options, PluginOptions, TypeBuilder, TypeGenerator, definePlugin as default, definePlugin, keywordTypeNodes, pluginKey, pluginName, resolve, useResolve };
|
package/dist/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { createRequire } from 'module';
|
2
|
-
import
|
3
|
-
import { createPlugin, getDependedPlugins,
|
4
|
-
import { pluginName as pluginName$1, resolve as resolve$1, isReference, OasBuilder, ImportsGenerator, OperationGenerator as OperationGenerator$1, useResolve as useResolve$1 } from '@kubb/swagger';
|
2
|
+
import path from 'path';
|
3
|
+
import { createPlugin, getDependedPlugins, FileManager, renderTemplate, getRelativePath, SchemaGenerator, getUniqueName, nameSorter, transformers } from '@kubb/core';
|
4
|
+
import { pluginName as pluginName$1, resolve as resolve$1, isReference, OasBuilder, refsSorter, ImportsGenerator, OperationGenerator as OperationGenerator$1, useResolve as useResolve$1 } from '@kubb/swagger';
|
5
5
|
import { camelCase, camelCaseTransformMerge, pascalCase, pascalCaseTransformMerge } from 'change-case';
|
6
6
|
import { createTypeAliasDeclaration, modifiers, createOmitDeclaration, appendJSDocToNode, createUnionDeclaration, createPropertySignature, createIndexSignature, createIntersectionDeclaration, createEnumDeclaration, createTupleDeclaration, print, createImportDeclaration } from '@kubb/parser';
|
7
7
|
import ts from 'typescript';
|
@@ -19,24 +19,29 @@ var keywordTypeNodes = {
|
|
19
19
|
null: factory.createLiteralTypeNode(factory.createToken(ts.SyntaxKind.NullKeyword))
|
20
20
|
};
|
21
21
|
function resolve(props) {
|
22
|
-
return resolve$1({ ...props
|
22
|
+
return resolve$1({ pluginKey, ...props });
|
23
23
|
}
|
24
24
|
|
25
25
|
// src/generators/TypeGenerator.ts
|
26
26
|
var { factory: factory2 } = ts;
|
27
|
-
var TypeGenerator = class
|
28
|
-
// Collect the types of all referenced schemas so we can export them later
|
29
|
-
static usedEnumNames = {};
|
27
|
+
var TypeGenerator = class extends SchemaGenerator {
|
30
28
|
refs = {};
|
31
29
|
extraNodes = [];
|
32
30
|
aliases = [];
|
33
31
|
// Keep track of already used type aliases
|
34
|
-
usedAliasNames = {};
|
35
|
-
caseOptions = {
|
32
|
+
#usedAliasNames = {};
|
33
|
+
#caseOptions = {
|
36
34
|
delimiter: "",
|
37
35
|
stripRegexp: /[^A-Z0-9$]/gi
|
38
36
|
};
|
39
|
-
constructor(options = {
|
37
|
+
constructor(options = {
|
38
|
+
usedEnumNames: {},
|
39
|
+
withJSDocs: true,
|
40
|
+
resolveName: ({ name }) => name,
|
41
|
+
enumType: "asConst",
|
42
|
+
dateType: "string",
|
43
|
+
optionalType: "questionToken"
|
44
|
+
}) {
|
40
45
|
super(options);
|
41
46
|
return this;
|
42
47
|
}
|
@@ -53,7 +58,7 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
53
58
|
}
|
54
59
|
const node = createTypeAliasDeclaration({
|
55
60
|
modifiers: [modifiers.export],
|
56
|
-
name: this.options.resolveName({ name: baseName
|
61
|
+
name: this.options.resolveName({ name: baseName }) || baseName,
|
57
62
|
type: keysToOmit?.length ? createOmitDeclaration({ keys: keysToOmit, type, nonNullable: true }) : type
|
58
63
|
});
|
59
64
|
if (description) {
|
@@ -99,7 +104,7 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
99
104
|
const members = Object.keys(properties).map((name) => {
|
100
105
|
const schema = properties[name];
|
101
106
|
const isRequired = required && required.includes(name);
|
102
|
-
let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ""} ${name}
|
107
|
+
let type = this.#getTypeFromSchema(schema, this.options.resolveName({ name: `${baseName || ""} ${name}` }));
|
103
108
|
if (!type) {
|
104
109
|
return null;
|
105
110
|
}
|
@@ -138,14 +143,14 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
138
143
|
/**
|
139
144
|
* Create a type alias for the schema referenced by the given ReferenceObject
|
140
145
|
*/
|
141
|
-
#getRefAlias(obj,
|
146
|
+
#getRefAlias(obj, _baseName) {
|
142
147
|
const { $ref } = obj;
|
143
148
|
let ref = this.refs[$ref];
|
144
149
|
if (ref) {
|
145
150
|
return factory2.createTypeReferenceNode(ref.propertyName, void 0);
|
146
151
|
}
|
147
|
-
const originalName = getUniqueName($ref.replace(/.+\//, ""), this
|
148
|
-
const propertyName = this.options.resolveName({ name: originalName
|
152
|
+
const originalName = getUniqueName($ref.replace(/.+\//, ""), this.#usedAliasNames);
|
153
|
+
const propertyName = this.options.resolveName({ name: originalName }) || originalName;
|
149
154
|
ref = this.refs[$ref] = {
|
150
155
|
propertyName,
|
151
156
|
originalName
|
@@ -215,7 +220,7 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
215
220
|
return and;
|
216
221
|
}
|
217
222
|
if (schema.enum && baseName) {
|
218
|
-
const enumName = getUniqueName(baseName,
|
223
|
+
const enumName = getUniqueName(baseName, this.options.usedEnumNames);
|
219
224
|
let enums = [...new Set(schema.enum)].map((key) => [key, key]);
|
220
225
|
if ("x-enumNames" in schema) {
|
221
226
|
enums = [...new Set(schema["x-enumNames"])].map((key, index) => {
|
@@ -224,13 +229,13 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
224
229
|
}
|
225
230
|
this.extraNodes.push(
|
226
231
|
...createEnumDeclaration({
|
227
|
-
name: camelCase(enumName, this
|
228
|
-
typeName: this.options.resolveName({ name: enumName
|
232
|
+
name: camelCase(enumName, this.#caseOptions),
|
233
|
+
typeName: this.options.resolveName({ name: enumName }),
|
229
234
|
enums,
|
230
235
|
type: this.options.enumType
|
231
236
|
})
|
232
237
|
);
|
233
|
-
return factory2.createTypeReferenceNode(this.options.resolveName({ name: enumName
|
238
|
+
return factory2.createTypeReferenceNode(this.options.resolveName({ name: enumName }), void 0);
|
234
239
|
}
|
235
240
|
if (schema.enum) {
|
236
241
|
return createUnionDeclaration({
|
@@ -287,15 +292,6 @@ var TypeGenerator = class _TypeGenerator extends SchemaGenerator {
|
|
287
292
|
};
|
288
293
|
|
289
294
|
// src/builders/TypeBuilder.ts
|
290
|
-
function refsSorter(a, b) {
|
291
|
-
if (Object.keys(a.import.refs)?.length < Object.keys(b.import.refs)?.length) {
|
292
|
-
return -1;
|
293
|
-
}
|
294
|
-
if (Object.keys(a.import.refs)?.length > Object.keys(b.import.refs)?.length) {
|
295
|
-
return 1;
|
296
|
-
}
|
297
|
-
return 0;
|
298
|
-
}
|
299
295
|
var TypeBuilder = class extends OasBuilder {
|
300
296
|
configure(options) {
|
301
297
|
if (options) {
|
@@ -310,6 +306,7 @@ var TypeBuilder = class extends OasBuilder {
|
|
310
306
|
const codes = [];
|
311
307
|
const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(nameSorter).map((operationSchema) => {
|
312
308
|
const generator = new TypeGenerator({
|
309
|
+
usedEnumNames: this.options.usedEnumNames,
|
313
310
|
withJSDocs: this.options.withJSDocs,
|
314
311
|
resolveName: this.options.resolveName,
|
315
312
|
enumType: this.options.enumType,
|
@@ -347,38 +344,39 @@ var TypeBuilder = class extends OasBuilder {
|
|
347
344
|
codes.unshift(print(nodes));
|
348
345
|
}
|
349
346
|
}
|
350
|
-
return combineCodes(codes);
|
347
|
+
return transformers.combineCodes(codes);
|
351
348
|
}
|
352
349
|
};
|
353
350
|
var OperationGenerator = class extends OperationGenerator$1 {
|
354
351
|
resolve(operation) {
|
355
|
-
const { pluginManager } = this.context;
|
352
|
+
const { pluginManager, plugin } = this.context;
|
356
353
|
return resolve$1({
|
357
354
|
operation,
|
358
355
|
resolveName: pluginManager.resolveName,
|
359
356
|
resolvePath: pluginManager.resolvePath,
|
360
|
-
|
357
|
+
pluginKey: plugin?.key
|
361
358
|
});
|
362
359
|
}
|
363
360
|
async all() {
|
364
361
|
return null;
|
365
362
|
}
|
366
363
|
async get(operation, schemas, options) {
|
367
|
-
const { mode, enumType, dateType, optionalType } = options;
|
368
|
-
const { pluginManager } = this.context;
|
364
|
+
const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
|
365
|
+
const { pluginManager, plugin } = this.context;
|
369
366
|
const type = this.resolve(operation);
|
370
367
|
const fileResolver = (name) => {
|
371
|
-
const root = pluginManager.resolvePath({ baseName: type.baseName,
|
368
|
+
const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
|
372
369
|
const resolvedTypeId = pluginManager.resolvePath({
|
373
370
|
baseName: `${name}.ts`,
|
374
|
-
|
371
|
+
pluginKey: plugin?.key
|
375
372
|
});
|
376
373
|
return getRelativePath(root, resolvedTypeId);
|
377
374
|
};
|
378
375
|
const source = new TypeBuilder({
|
376
|
+
usedEnumNames,
|
379
377
|
fileResolver: mode === "file" ? void 0 : fileResolver,
|
380
378
|
withJSDocs: true,
|
381
|
-
resolveName: pluginManager.resolveName,
|
379
|
+
resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
|
382
380
|
enumType,
|
383
381
|
optionalType,
|
384
382
|
dateType
|
@@ -388,27 +386,28 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
388
386
|
baseName: type.baseName,
|
389
387
|
source,
|
390
388
|
meta: {
|
391
|
-
|
389
|
+
pluginKey: plugin.key,
|
392
390
|
tag: operation.getTags()[0]?.name
|
393
391
|
}
|
394
392
|
};
|
395
393
|
}
|
396
394
|
async post(operation, schemas, options) {
|
397
|
-
const { mode, enumType, dateType, optionalType } = options;
|
398
|
-
const { pluginManager } = this.context;
|
395
|
+
const { mode, enumType, dateType, optionalType, usedEnumNames } = options;
|
396
|
+
const { pluginManager, plugin } = this.context;
|
399
397
|
const type = this.resolve(operation);
|
400
398
|
const fileResolver = (name) => {
|
401
|
-
const root = pluginManager.resolvePath({ baseName: type.baseName,
|
399
|
+
const root = pluginManager.resolvePath({ baseName: type.baseName, pluginKey: plugin?.key, options: { tag: operation.getTags()[0]?.name } });
|
402
400
|
const resolvedTypeId = pluginManager.resolvePath({
|
403
401
|
baseName: `${name}.ts`,
|
404
|
-
|
402
|
+
pluginKey: plugin?.key
|
405
403
|
});
|
406
404
|
return getRelativePath(root, resolvedTypeId);
|
407
405
|
};
|
408
406
|
const source = new TypeBuilder({
|
407
|
+
usedEnumNames,
|
409
408
|
fileResolver: mode === "file" ? void 0 : fileResolver,
|
410
409
|
withJSDocs: true,
|
411
|
-
resolveName: pluginManager.resolveName,
|
410
|
+
resolveName: (params) => pluginManager.resolveName({ ...params, pluginKey: plugin?.key }),
|
412
411
|
enumType,
|
413
412
|
optionalType,
|
414
413
|
dateType
|
@@ -418,7 +417,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
418
417
|
baseName: type.baseName,
|
419
418
|
source,
|
420
419
|
meta: {
|
421
|
-
|
420
|
+
pluginKey: plugin.key,
|
422
421
|
tag: operation.getTags()[0]?.name
|
423
422
|
}
|
424
423
|
};
|
@@ -436,6 +435,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
436
435
|
|
437
436
|
// src/plugin.ts
|
438
437
|
var pluginName = "swagger-ts";
|
438
|
+
var pluginKey = ["schema", pluginName];
|
439
439
|
var definePlugin = createPlugin((options) => {
|
440
440
|
const {
|
441
441
|
output = "types",
|
@@ -445,7 +445,8 @@ var definePlugin = createPlugin((options) => {
|
|
445
445
|
enumType = "asConst",
|
446
446
|
dateType = "string",
|
447
447
|
optionalType = "questionToken",
|
448
|
-
transformers = {}
|
448
|
+
transformers: transformers2 = {},
|
449
|
+
exportAs
|
449
450
|
} = options;
|
450
451
|
const template = groupBy?.output ? groupBy.output : `${output}/{{tag}}Controller`;
|
451
452
|
let pluginsOptions;
|
@@ -458,42 +459,44 @@ var definePlugin = createPlugin((options) => {
|
|
458
459
|
return true;
|
459
460
|
},
|
460
461
|
resolvePath(baseName, directory, options2) {
|
461
|
-
const root =
|
462
|
-
const mode =
|
462
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
463
|
+
const mode = FileManager.getMode(path.resolve(root, output));
|
463
464
|
if (mode === "file") {
|
464
|
-
return
|
465
|
+
return path.resolve(root, output);
|
465
466
|
}
|
466
467
|
if (options2?.tag && groupBy?.type === "tag") {
|
467
468
|
const tag = camelCase(options2.tag, { delimiter: "", transform: camelCaseTransformMerge });
|
468
|
-
return
|
469
|
+
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
469
470
|
}
|
470
|
-
return
|
471
|
+
return path.resolve(root, output, baseName);
|
471
472
|
},
|
472
473
|
resolveName(name) {
|
473
474
|
const resolvedName = pascalCase(name, { delimiter: "", stripRegexp: /[^A-Z0-9$]/gi, transform: pascalCaseTransformMerge });
|
474
|
-
return
|
475
|
+
return transformers2?.name?.(resolvedName) || resolvedName;
|
475
476
|
},
|
476
|
-
async writeFile(source,
|
477
|
-
if (!
|
477
|
+
async writeFile(source, writePath) {
|
478
|
+
if (!writePath.endsWith(".ts") || !source) {
|
478
479
|
return;
|
479
480
|
}
|
480
|
-
|
481
|
+
return this.fileManager.write(source, writePath);
|
481
482
|
},
|
482
483
|
async buildStart() {
|
483
484
|
const [swaggerPlugin] = pluginsOptions;
|
484
485
|
const oas = await swaggerPlugin.api.getOas();
|
485
486
|
const schemas = await swaggerPlugin.api.getSchemas();
|
486
|
-
const root =
|
487
|
-
const mode =
|
487
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
488
|
+
const mode = FileManager.getMode(path.resolve(root, output));
|
489
|
+
const usedEnumNames = {};
|
488
490
|
if (mode === "directory") {
|
489
491
|
const builder = await new TypeBuilder({
|
490
|
-
|
492
|
+
usedEnumNames,
|
493
|
+
resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),
|
491
494
|
fileResolver: (name) => {
|
492
495
|
const resolvedTypeId = this.resolvePath({
|
493
496
|
baseName: `${name}.ts`,
|
494
|
-
|
497
|
+
pluginKey: this.plugin.key
|
495
498
|
});
|
496
|
-
const root2 = this.resolvePath({ baseName: ``,
|
499
|
+
const root2 = this.resolvePath({ baseName: ``, pluginKey: this.plugin.key });
|
497
500
|
return getRelativePath(root2, resolvedTypeId);
|
498
501
|
},
|
499
502
|
withJSDocs: true,
|
@@ -508,16 +511,16 @@ var definePlugin = createPlugin((options) => {
|
|
508
511
|
});
|
509
512
|
});
|
510
513
|
const mapFolderSchema = async ([name]) => {
|
511
|
-
const
|
512
|
-
if (!
|
514
|
+
const resolvedPath = this.resolvePath({ baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`, pluginKey: this.plugin.key });
|
515
|
+
if (!resolvedPath) {
|
513
516
|
return null;
|
514
517
|
}
|
515
518
|
return this.addFile({
|
516
|
-
path,
|
517
|
-
baseName: `${this.resolveName({ name,
|
519
|
+
path: resolvedPath,
|
520
|
+
baseName: `${this.resolveName({ name, pluginKey: this.plugin.key })}.ts`,
|
518
521
|
source: builder.print(name),
|
519
522
|
meta: {
|
520
|
-
|
523
|
+
pluginKey: this.plugin.key
|
521
524
|
}
|
522
525
|
});
|
523
526
|
};
|
@@ -526,7 +529,8 @@ var definePlugin = createPlugin((options) => {
|
|
526
529
|
}
|
527
530
|
if (mode === "file") {
|
528
531
|
const builder = new TypeBuilder({
|
529
|
-
|
532
|
+
usedEnumNames,
|
533
|
+
resolveName: (params) => this.resolveName({ pluginKey: this.plugin.key, ...params }),
|
530
534
|
withJSDocs: true,
|
531
535
|
enumType,
|
532
536
|
dateType,
|
@@ -538,16 +542,16 @@ var definePlugin = createPlugin((options) => {
|
|
538
542
|
name
|
539
543
|
});
|
540
544
|
});
|
541
|
-
const
|
542
|
-
if (!
|
545
|
+
const resolvedPath = this.resolvePath({ baseName: "", pluginKey: this.plugin.key });
|
546
|
+
if (!resolvedPath) {
|
543
547
|
return;
|
544
548
|
}
|
545
549
|
await this.addFile({
|
546
|
-
path,
|
547
|
-
baseName: `${this.resolveName({ name: output,
|
550
|
+
path: resolvedPath,
|
551
|
+
baseName: `${this.resolveName({ name: output, pluginKey: this.plugin.key })}.ts`,
|
548
552
|
source: builder.print(),
|
549
553
|
meta: {
|
550
|
-
|
554
|
+
pluginKey: this.plugin.key
|
551
555
|
}
|
552
556
|
});
|
553
557
|
}
|
@@ -556,11 +560,13 @@ var definePlugin = createPlugin((options) => {
|
|
556
560
|
mode,
|
557
561
|
enumType,
|
558
562
|
dateType,
|
559
|
-
optionalType
|
563
|
+
optionalType,
|
564
|
+
usedEnumNames
|
560
565
|
},
|
561
566
|
{
|
562
567
|
oas,
|
563
568
|
pluginManager: this.pluginManager,
|
569
|
+
plugin: this.plugin,
|
564
570
|
contentType: swaggerPlugin.api.contentType,
|
565
571
|
skipBy,
|
566
572
|
overrideBy
|
@@ -573,21 +579,41 @@ var definePlugin = createPlugin((options) => {
|
|
573
579
|
if (this.config.output.write === false) {
|
574
580
|
return;
|
575
581
|
}
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
582
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
583
|
+
await this.fileManager.addIndexes({
|
584
|
+
root,
|
585
|
+
extName: ".ts",
|
586
|
+
meta: { pluginKey: this.plugin.key },
|
587
|
+
options: {
|
588
|
+
map: (file) => {
|
589
|
+
return {
|
590
|
+
...file,
|
591
|
+
exports: file.exports?.map((item) => {
|
592
|
+
if (exportAs) {
|
593
|
+
return {
|
594
|
+
...item,
|
595
|
+
name: exportAs,
|
596
|
+
asAlias: !!exportAs
|
597
|
+
};
|
598
|
+
}
|
599
|
+
return item;
|
600
|
+
})
|
601
|
+
};
|
602
|
+
},
|
603
|
+
output,
|
604
|
+
isTypeOnly: true
|
605
|
+
}
|
606
|
+
});
|
581
607
|
}
|
582
608
|
};
|
583
609
|
});
|
584
610
|
function useResolve(props = {}) {
|
585
|
-
return useResolve$1({
|
611
|
+
return useResolve$1({ pluginKey, ...props });
|
586
612
|
}
|
587
613
|
|
588
614
|
// src/index.ts
|
589
615
|
var src_default = definePlugin;
|
590
616
|
|
591
|
-
export { OperationGenerator, TypeBuilder, TypeGenerator, src_default as default, definePlugin, keywordTypeNodes, pluginName, resolve, useResolve };
|
617
|
+
export { OperationGenerator, TypeBuilder, TypeGenerator, src_default as default, definePlugin, keywordTypeNodes, pluginKey, pluginName, resolve, useResolve };
|
592
618
|
//# sourceMappingURL=out.js.map
|
593
619
|
//# sourceMappingURL=index.js.map
|