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