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