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