@kubb/swagger-ts 1.1.7 → 1.1.8
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/README.md +34 -26
- package/dist/index.cjs +12 -18
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -18
- package/package.json +26 -25
- package/src/builders/TypeBuilder.ts +2 -2
- package/src/generators/OperationGenerator.ts +4 -4
- package/src/generators/TypeGenerator.ts +18 -22
- package/src/plugin.ts +2 -2
package/README.md
CHANGED
|
@@ -6,37 +6,45 @@
|
|
|
6
6
|
<p>
|
|
7
7
|
Swagger integration for TypeScript to generate all the different types based on an OpenAPI specification.
|
|
8
8
|
</p>
|
|
9
|
+
|
|
10
|
+
<img src="https://raw.githubusercontent.com/kubb-project/kubb/main/assets/banner.png" alt="logo" height="auto" />
|
|
9
11
|
|
|
10
|
-
<!-- Badges -->
|
|
11
|
-
<p>
|
|
12
|
-
<a href="https://www.npmjs.com/package/@kubb/swagger-ts">
|
|
12
|
+
<!-- Badges -->
|
|
13
|
+
<p>
|
|
14
|
+
<a href="https://www.npmjs.com/package/@kubb/swagger-ts" target="_blank">
|
|
13
15
|
<img alt="npm version" src="https://img.shields.io/npm/v/@kubb/swagger-ts?style=for-the-badge"/>
|
|
14
16
|
</a>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
</a>
|
|
18
|
-
<a href="https://www.npmjs.com/package/@kubb/swagger-ts">
|
|
17
|
+
|
|
18
|
+
<a href="https://www.npmjs.com/package/@kubb/swagger-ts" target="_blank">
|
|
19
19
|
<img alt="npm downloads" src="https://img.shields.io/npm/dm/@kubb/swagger-ts?style=for-the-badge"/>
|
|
20
20
|
</a>
|
|
21
|
-
</p>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<p>
|
|
24
|
+
<a href="https://www.npmjs.com/package/@kubb/swagger-ts" target="_blank">
|
|
25
|
+
<img alt="Minified size" src="https://img.shields.io/bundlephobia/min/@kubb/swagger-ts?style=for-the-badge"/>
|
|
26
|
+
</a>
|
|
27
|
+
|
|
28
|
+
<a href="https://www.npmjs.com/package/@kubb/swagger-ts" target="_blank">
|
|
29
|
+
<img alt="Coverage" src="https://img.shields.io/codecov/c/github/kubb-project/kubb?style=for-the-badge"/>
|
|
30
|
+
</a>
|
|
31
|
+
|
|
32
|
+
<a href="https://www.npmjs.com/package/@kubb/swagger-ts" target="_blank">
|
|
33
|
+
<img alt="Build status" src="https://img.shields.io/github/actions/workflow/status/kubb-project/kubb/ci.yaml?style=for-the-badge"/>
|
|
34
|
+
</a>
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
38
|
+
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
39
|
+
</p>
|
|
22
40
|
|
|
23
|
-
<h4>
|
|
24
|
-
<a href="https://codesandbox.io/s/github/kubb-project/kubb/tree/main/examples/simple">View Demo</a>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
<h4>
|
|
42
|
+
<a href="https://codesandbox.io/s/github/kubb-project/kubb/tree/main/examples/simple" target="_blank">View Demo</a>
|
|
43
|
+
<span> · </span>
|
|
44
|
+
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
45
|
+
<span> · </span>
|
|
46
|
+
<a href="https://github.com/kubb-project/kubb/issues/" target="_blank">Report Bug</a>
|
|
47
|
+
<span> · </span>
|
|
48
|
+
<a href="https://github.com/kubb-project/kubb/issues/" target="_blank">Request Feature</a>
|
|
31
49
|
</h4>
|
|
32
50
|
</div>
|
|
33
|
-
|
|
34
|
-
<br />
|
|
35
|
-
|
|
36
|
-
<!-- About the Project
|
|
37
|
-
## :star2: About the Project
|
|
38
|
-
|
|
39
|
-
<div align="center">
|
|
40
|
-
<img src="assets/screenshot.jpg" alt="screenshot" />
|
|
41
|
-
</div>
|
|
42
|
-
-->
|
package/dist/index.cjs
CHANGED
|
@@ -8,13 +8,11 @@ var core = require('@kubb/core');
|
|
|
8
8
|
var swagger = require('@kubb/swagger');
|
|
9
9
|
var changeCase = require('change-case');
|
|
10
10
|
var tsCodegen = require('@kubb/ts-codegen');
|
|
11
|
-
var uniqueId = require('lodash.uniqueid');
|
|
12
11
|
var ts = require('typescript');
|
|
13
12
|
|
|
14
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
14
|
|
|
16
15
|
var pathParser__default = /*#__PURE__*/_interopDefault(pathParser);
|
|
17
|
-
var uniqueId__default = /*#__PURE__*/_interopDefault(uniqueId);
|
|
18
16
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
19
17
|
|
|
20
18
|
module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href)));
|
|
@@ -56,7 +54,7 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
56
54
|
return this.extraNodes;
|
|
57
55
|
}
|
|
58
56
|
const node = tsCodegen.createTypeAliasDeclaration({
|
|
59
|
-
modifiers: [tsCodegen.
|
|
57
|
+
modifiers: [tsCodegen.modifiers.export],
|
|
60
58
|
name: this.options.resolveName({ name: baseName, pluginName }) || baseName,
|
|
61
59
|
type
|
|
62
60
|
});
|
|
@@ -152,7 +150,7 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
152
150
|
ref = this.refs[$ref] = {
|
|
153
151
|
propertyName,
|
|
154
152
|
originalName,
|
|
155
|
-
name:
|
|
153
|
+
name: core.uniqueId(propertyName)
|
|
156
154
|
};
|
|
157
155
|
return factory2.createTypeReferenceNode(ref.name, void 0);
|
|
158
156
|
}
|
|
@@ -187,9 +185,7 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
187
185
|
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean)
|
|
188
186
|
});
|
|
189
187
|
}
|
|
190
|
-
return
|
|
191
|
-
nodes: [union]
|
|
192
|
-
});
|
|
188
|
+
return union;
|
|
193
189
|
}
|
|
194
190
|
if (schema.anyOf) ;
|
|
195
191
|
if (schema.allOf) {
|
|
@@ -206,9 +202,7 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
206
202
|
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean)
|
|
207
203
|
});
|
|
208
204
|
}
|
|
209
|
-
return
|
|
210
|
-
nodes: [and]
|
|
211
|
-
});
|
|
205
|
+
return and;
|
|
212
206
|
}
|
|
213
207
|
if (schema.enum && baseName) {
|
|
214
208
|
const enumName = core.getUniqueName(baseName, _TypeGenerator.usedEnumNames);
|
|
@@ -300,7 +294,7 @@ var TypeBuilder = class extends swagger.OasBuilder {
|
|
|
300
294
|
}
|
|
301
295
|
return this;
|
|
302
296
|
}
|
|
303
|
-
|
|
297
|
+
print(name) {
|
|
304
298
|
const codes = [];
|
|
305
299
|
const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(core.nameSorter).map((operationSchema) => {
|
|
306
300
|
const generator = new TypeGenerator(this.oas, {
|
|
@@ -322,7 +316,7 @@ var TypeBuilder = class extends swagger.OasBuilder {
|
|
|
322
316
|
});
|
|
323
317
|
if (this.config.withImports) {
|
|
324
318
|
const importsGenerator = new swagger.ImportsGenerator({ fileResolver: this.config.fileResolver });
|
|
325
|
-
const importMeta =
|
|
319
|
+
const importMeta = importsGenerator.build(generated.map((item) => item.import));
|
|
326
320
|
if (importMeta) {
|
|
327
321
|
const nodes = importMeta.map((item) => {
|
|
328
322
|
return tsCodegen.createImportDeclaration({
|
|
@@ -366,7 +360,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
366
360
|
});
|
|
367
361
|
return core.getRelativePath(root, resolvedTypeId);
|
|
368
362
|
};
|
|
369
|
-
const source =
|
|
363
|
+
const source = new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
370
364
|
return {
|
|
371
365
|
path: type.filePath,
|
|
372
366
|
fileName: type.fileName,
|
|
@@ -384,7 +378,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
384
378
|
});
|
|
385
379
|
return core.getRelativePath(root, resolvedTypeId);
|
|
386
380
|
};
|
|
387
|
-
const source =
|
|
381
|
+
const source = new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
388
382
|
return {
|
|
389
383
|
path: type.filePath,
|
|
390
384
|
fileName: type.fileName,
|
|
@@ -402,7 +396,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
402
396
|
});
|
|
403
397
|
return core.getRelativePath(root, resolvedTypeId);
|
|
404
398
|
};
|
|
405
|
-
const source =
|
|
399
|
+
const source = new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
406
400
|
return {
|
|
407
401
|
path: type.filePath,
|
|
408
402
|
fileName: type.fileName,
|
|
@@ -420,7 +414,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
420
414
|
});
|
|
421
415
|
return core.getRelativePath(root, resolvedTypeId);
|
|
422
416
|
};
|
|
423
|
-
const source =
|
|
417
|
+
const source = new TypeBuilder(oas).add(schemas.pathParams).add(schemas.request).add(schemas.queryParams).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
424
418
|
return {
|
|
425
419
|
path: type.filePath,
|
|
426
420
|
fileName: type.fileName,
|
|
@@ -499,7 +493,7 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
499
493
|
return this.addFile({
|
|
500
494
|
path,
|
|
501
495
|
fileName: `${this.resolveName({ name, pluginName })}.ts`,
|
|
502
|
-
source:
|
|
496
|
+
source: builder.print(name)
|
|
503
497
|
});
|
|
504
498
|
};
|
|
505
499
|
const promises = Object.entries(schemas).map(mapFolderSchema);
|
|
@@ -524,7 +518,7 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
524
518
|
await this.addFile({
|
|
525
519
|
path,
|
|
526
520
|
fileName: `${this.resolveName({ name: output, pluginName })}.ts`,
|
|
527
|
-
source:
|
|
521
|
+
source: builder.print()
|
|
528
522
|
});
|
|
529
523
|
}
|
|
530
524
|
const operationGenerator = new OperationGenerator({
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import pathParser from 'node:path';
|
|
3
|
-
import { createPlugin, validatePlugins, getPathMode, renderTemplate, getRelativePath, writeIndexes, nameSorter, SchemaGenerator, getUniqueName } from '@kubb/core';
|
|
3
|
+
import { createPlugin, validatePlugins, getPathMode, renderTemplate, getRelativePath, writeIndexes, nameSorter, SchemaGenerator, getUniqueName, uniqueId } from '@kubb/core';
|
|
4
4
|
import { pluginName as pluginName$1, OasBuilder, ImportsGenerator, OperationGenerator as OperationGenerator$1, isReference } from '@kubb/swagger';
|
|
5
5
|
import { pascalCase, pascalCaseTransformMerge, camelCase } from 'change-case';
|
|
6
|
-
import { print, createImportDeclaration, createTypeAliasDeclaration,
|
|
7
|
-
import uniqueId from 'lodash.uniqueid';
|
|
6
|
+
import { print, createImportDeclaration, createTypeAliasDeclaration, modifiers, appendJSDocToNode, createUnionDeclaration, createPropertySignature, createIndexSignature, createIntersectionDeclaration, createEnumDeclaration, createTupleDeclaration } from '@kubb/ts-codegen';
|
|
8
7
|
import ts from 'typescript';
|
|
9
8
|
|
|
10
9
|
createRequire(import.meta.url);
|
|
@@ -46,7 +45,7 @@ var _TypeGenerator = class extends SchemaGenerator {
|
|
|
46
45
|
return this.extraNodes;
|
|
47
46
|
}
|
|
48
47
|
const node = createTypeAliasDeclaration({
|
|
49
|
-
modifiers: [
|
|
48
|
+
modifiers: [modifiers.export],
|
|
50
49
|
name: this.options.resolveName({ name: baseName, pluginName }) || baseName,
|
|
51
50
|
type
|
|
52
51
|
});
|
|
@@ -177,9 +176,7 @@ var _TypeGenerator = class extends SchemaGenerator {
|
|
|
177
176
|
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean)
|
|
178
177
|
});
|
|
179
178
|
}
|
|
180
|
-
return
|
|
181
|
-
nodes: [union]
|
|
182
|
-
});
|
|
179
|
+
return union;
|
|
183
180
|
}
|
|
184
181
|
if (schema.anyOf) ;
|
|
185
182
|
if (schema.allOf) {
|
|
@@ -196,9 +193,7 @@ var _TypeGenerator = class extends SchemaGenerator {
|
|
|
196
193
|
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean)
|
|
197
194
|
});
|
|
198
195
|
}
|
|
199
|
-
return
|
|
200
|
-
nodes: [and]
|
|
201
|
-
});
|
|
196
|
+
return and;
|
|
202
197
|
}
|
|
203
198
|
if (schema.enum && baseName) {
|
|
204
199
|
const enumName = getUniqueName(baseName, _TypeGenerator.usedEnumNames);
|
|
@@ -290,7 +285,7 @@ var TypeBuilder = class extends OasBuilder {
|
|
|
290
285
|
}
|
|
291
286
|
return this;
|
|
292
287
|
}
|
|
293
|
-
|
|
288
|
+
print(name) {
|
|
294
289
|
const codes = [];
|
|
295
290
|
const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(nameSorter).map((operationSchema) => {
|
|
296
291
|
const generator = new TypeGenerator(this.oas, {
|
|
@@ -312,7 +307,7 @@ var TypeBuilder = class extends OasBuilder {
|
|
|
312
307
|
});
|
|
313
308
|
if (this.config.withImports) {
|
|
314
309
|
const importsGenerator = new ImportsGenerator({ fileResolver: this.config.fileResolver });
|
|
315
|
-
const importMeta =
|
|
310
|
+
const importMeta = importsGenerator.build(generated.map((item) => item.import));
|
|
316
311
|
if (importMeta) {
|
|
317
312
|
const nodes = importMeta.map((item) => {
|
|
318
313
|
return createImportDeclaration({
|
|
@@ -356,7 +351,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
356
351
|
});
|
|
357
352
|
return getRelativePath(root, resolvedTypeId);
|
|
358
353
|
};
|
|
359
|
-
const source =
|
|
354
|
+
const source = new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
360
355
|
return {
|
|
361
356
|
path: type.filePath,
|
|
362
357
|
fileName: type.fileName,
|
|
@@ -374,7 +369,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
374
369
|
});
|
|
375
370
|
return getRelativePath(root, resolvedTypeId);
|
|
376
371
|
};
|
|
377
|
-
const source =
|
|
372
|
+
const source = new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
378
373
|
return {
|
|
379
374
|
path: type.filePath,
|
|
380
375
|
fileName: type.fileName,
|
|
@@ -392,7 +387,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
392
387
|
});
|
|
393
388
|
return getRelativePath(root, resolvedTypeId);
|
|
394
389
|
};
|
|
395
|
-
const source =
|
|
390
|
+
const source = new TypeBuilder(oas).add(schemas.pathParams).add(schemas.queryParams).add(schemas.request).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
396
391
|
return {
|
|
397
392
|
path: type.filePath,
|
|
398
393
|
fileName: type.fileName,
|
|
@@ -410,7 +405,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
410
405
|
});
|
|
411
406
|
return getRelativePath(root, resolvedTypeId);
|
|
412
407
|
};
|
|
413
|
-
const source =
|
|
408
|
+
const source = new TypeBuilder(oas).add(schemas.pathParams).add(schemas.request).add(schemas.queryParams).add(schemas.response).add(schemas.errors).configure({ fileResolver: mode === "file" ? void 0 : fileResolver, withJSDocs: true, resolveName, enumType }).print();
|
|
414
409
|
return {
|
|
415
410
|
path: type.filePath,
|
|
416
411
|
fileName: type.fileName,
|
|
@@ -489,7 +484,7 @@ var definePlugin = createPlugin((options) => {
|
|
|
489
484
|
return this.addFile({
|
|
490
485
|
path,
|
|
491
486
|
fileName: `${this.resolveName({ name, pluginName })}.ts`,
|
|
492
|
-
source:
|
|
487
|
+
source: builder.print(name)
|
|
493
488
|
});
|
|
494
489
|
};
|
|
495
490
|
const promises = Object.entries(schemas).map(mapFolderSchema);
|
|
@@ -514,7 +509,7 @@ var definePlugin = createPlugin((options) => {
|
|
|
514
509
|
await this.addFile({
|
|
515
510
|
path,
|
|
516
511
|
fileName: `${this.resolveName({ name: output, pluginName })}.ts`,
|
|
517
|
-
source:
|
|
512
|
+
source: builder.print()
|
|
518
513
|
});
|
|
519
514
|
}
|
|
520
515
|
const operationGenerator = new OperationGenerator({
|
package/package.json
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/swagger-ts",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Generator swagger-ts",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git://github.com/kubb-project/kubb.git",
|
|
8
|
-
"directory": "packages/swagger-ts"
|
|
9
|
-
},
|
|
10
|
-
"license": "MIT",
|
|
11
|
-
"author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
|
|
12
5
|
"keywords": [
|
|
13
6
|
"typescript",
|
|
14
7
|
"plugins",
|
|
@@ -17,11 +10,15 @@
|
|
|
17
10
|
"swagger",
|
|
18
11
|
"openapi"
|
|
19
12
|
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git://github.com/kubb-project/kubb.git",
|
|
16
|
+
"directory": "packages/swagger-ts"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"type": "module",
|
|
22
|
-
"main": "dist/index.js",
|
|
23
|
-
"module": "dist/index.js",
|
|
24
|
-
"types": "./dist/index.d.ts",
|
|
25
22
|
"exports": {
|
|
26
23
|
".": {
|
|
27
24
|
"types": "./dist/index.d.ts",
|
|
@@ -31,6 +28,9 @@
|
|
|
31
28
|
},
|
|
32
29
|
"./package.json": "./package.json"
|
|
33
30
|
},
|
|
31
|
+
"main": "dist/index.js",
|
|
32
|
+
"module": "dist/index.js",
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
34
|
"files": [
|
|
35
35
|
"dist",
|
|
36
36
|
"src",
|
|
@@ -39,35 +39,36 @@
|
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"change-case": "^4.1.2",
|
|
42
|
-
"lodash.uniqueid": "^4.0.1",
|
|
43
42
|
"typescript": "^5.1.3",
|
|
44
|
-
"@kubb/core": "1.1.
|
|
45
|
-
"@kubb/swagger": "1.1.
|
|
46
|
-
"@kubb/ts-codegen": "1.1.
|
|
43
|
+
"@kubb/core": "1.1.8",
|
|
44
|
+
"@kubb/swagger": "1.1.8",
|
|
45
|
+
"@kubb/ts-codegen": "1.1.8"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"eslint": "^8.42.0",
|
|
50
49
|
"tsup": "^6.7.0",
|
|
51
|
-
"@
|
|
50
|
+
"@kubb/eslint-config": "0.1.0",
|
|
52
51
|
"@kubb/tsup-config": "0.1.0",
|
|
53
|
-
"@kubb/
|
|
52
|
+
"@kubb/typescript-config": "0.1.0"
|
|
53
|
+
},
|
|
54
|
+
"packageManager": "pnpm@8.3.0",
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18",
|
|
57
|
+
"pnpm": ">=8.3.0"
|
|
54
58
|
},
|
|
55
59
|
"publishConfig": {
|
|
56
60
|
"access": "public",
|
|
57
61
|
"registry": "https://registry.npmjs.org/"
|
|
58
62
|
},
|
|
59
|
-
"engines": {
|
|
60
|
-
"node": ">=18",
|
|
61
|
-
"pnpm": ">=8"
|
|
62
|
-
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "tsup",
|
|
65
|
-
"
|
|
66
|
-
"release": "pnpm publish --no-git-check",
|
|
65
|
+
"clean": "rimraf ./dist",
|
|
67
66
|
"lint": "eslint \"**/*.{ts,tsx}\"",
|
|
68
67
|
"lint-fix": "eslint \"**/*.{ts,tsx}\" --quiet --fix",
|
|
68
|
+
"release": "pnpm publish --no-git-check",
|
|
69
|
+
"start": "tsup --watch",
|
|
69
70
|
"test": "vitest --passWithNoTests",
|
|
70
|
-
"
|
|
71
|
-
"
|
|
71
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false",
|
|
72
|
+
"upgrade": "pnpm update"
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -39,7 +39,7 @@ export class TypeBuilder extends OasBuilder<Config> {
|
|
|
39
39
|
return this
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
print(name?: string): string {
|
|
43
43
|
const codes: string[] = []
|
|
44
44
|
|
|
45
45
|
const generated = this.items
|
|
@@ -69,7 +69,7 @@ export class TypeBuilder extends OasBuilder<Config> {
|
|
|
69
69
|
|
|
70
70
|
if (this.config.withImports) {
|
|
71
71
|
const importsGenerator = new ImportsGenerator({ fileResolver: this.config.fileResolver })
|
|
72
|
-
const importMeta =
|
|
72
|
+
const importMeta = importsGenerator.build(generated.map((item) => item.import))
|
|
73
73
|
|
|
74
74
|
if (importMeta) {
|
|
75
75
|
const nodes = importMeta.map((item) => {
|
|
@@ -55,7 +55,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
55
55
|
return getRelativePath(root, resolvedTypeId)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const source =
|
|
58
|
+
const source = new TypeBuilder(oas)
|
|
59
59
|
.add(schemas.pathParams)
|
|
60
60
|
.add(schemas.queryParams)
|
|
61
61
|
.add(schemas.response)
|
|
@@ -87,7 +87,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
87
87
|
return getRelativePath(root, resolvedTypeId)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
const source =
|
|
90
|
+
const source = new TypeBuilder(oas)
|
|
91
91
|
.add(schemas.pathParams)
|
|
92
92
|
.add(schemas.queryParams)
|
|
93
93
|
.add(schemas.request)
|
|
@@ -120,7 +120,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
120
120
|
return getRelativePath(root, resolvedTypeId)
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
const source =
|
|
123
|
+
const source = new TypeBuilder(oas)
|
|
124
124
|
.add(schemas.pathParams)
|
|
125
125
|
.add(schemas.queryParams)
|
|
126
126
|
.add(schemas.request)
|
|
@@ -153,7 +153,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
153
153
|
return getRelativePath(root, resolvedTypeId)
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
const source =
|
|
156
|
+
const source = new TypeBuilder(oas)
|
|
157
157
|
.add(schemas.pathParams)
|
|
158
158
|
.add(schemas.request)
|
|
159
159
|
.add(schemas.queryParams)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
|
-
import { getUniqueName, SchemaGenerator } from '@kubb/core'
|
|
2
|
+
import { getUniqueName, SchemaGenerator, uniqueId } from '@kubb/core'
|
|
3
3
|
import { isReference } from '@kubb/swagger'
|
|
4
4
|
import {
|
|
5
5
|
appendJSDocToNode,
|
|
@@ -10,11 +10,10 @@ import {
|
|
|
10
10
|
createTupleDeclaration,
|
|
11
11
|
createTypeAliasDeclaration,
|
|
12
12
|
createUnionDeclaration,
|
|
13
|
-
|
|
13
|
+
modifiers,
|
|
14
14
|
} from '@kubb/ts-codegen'
|
|
15
15
|
|
|
16
16
|
import { camelCase, pascalCase } from 'change-case'
|
|
17
|
-
import uniqueId from 'lodash.uniqueid'
|
|
18
17
|
import ts from 'typescript'
|
|
19
18
|
|
|
20
19
|
import { pluginName } from '../plugin.ts'
|
|
@@ -22,6 +21,7 @@ import { keywordTypeNodes } from '../utils/index.ts'
|
|
|
22
21
|
|
|
23
22
|
import type { PluginContext } from '@kubb/core'
|
|
24
23
|
import type { Oas, OpenAPIV3, Refs } from '@kubb/swagger'
|
|
24
|
+
import type { ArrayTwoOrMore } from '@kubb/ts-codegen'
|
|
25
25
|
|
|
26
26
|
const { factory } = ts
|
|
27
27
|
|
|
@@ -60,7 +60,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
const node = createTypeAliasDeclaration({
|
|
63
|
-
modifiers: [
|
|
63
|
+
modifiers: [modifiers.export],
|
|
64
64
|
name: this.options.resolveName({ name: baseName, pluginName }) || baseName,
|
|
65
65
|
type,
|
|
66
66
|
})
|
|
@@ -212,22 +212,20 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
212
212
|
const union = factory.createParenthesizedType(
|
|
213
213
|
createUnionDeclaration({
|
|
214
214
|
nodes: schema.oneOf
|
|
215
|
-
.map((item) => {
|
|
216
|
-
return this.getBaseTypeFromSchema(item)
|
|
215
|
+
.map((item: any) => {
|
|
216
|
+
return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)
|
|
217
217
|
})
|
|
218
|
-
.filter(Boolean) as ts.TypeNode
|
|
218
|
+
.filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
219
219
|
})
|
|
220
220
|
)
|
|
221
221
|
|
|
222
222
|
if (schemaWithoutOneOf.properties) {
|
|
223
223
|
return createIntersectionDeclaration({
|
|
224
|
-
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ts.TypeNode
|
|
224
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
225
225
|
})
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
return
|
|
229
|
-
nodes: [union],
|
|
230
|
-
})
|
|
228
|
+
return union
|
|
231
229
|
}
|
|
232
230
|
|
|
233
231
|
if (schema.anyOf) {
|
|
@@ -240,22 +238,20 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
240
238
|
const and = factory.createParenthesizedType(
|
|
241
239
|
factory.createIntersectionTypeNode(
|
|
242
240
|
schema.allOf
|
|
243
|
-
.map((item) => {
|
|
244
|
-
return this.getBaseTypeFromSchema(item)
|
|
241
|
+
.map((item: any) => {
|
|
242
|
+
return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)
|
|
245
243
|
})
|
|
246
|
-
.filter(Boolean) as ts.TypeNode
|
|
244
|
+
.filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>
|
|
247
245
|
)
|
|
248
246
|
)
|
|
249
247
|
|
|
250
248
|
if (schemaWithoutAllOf.properties) {
|
|
251
249
|
return createIntersectionDeclaration({
|
|
252
|
-
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ts.TypeNode
|
|
250
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
253
251
|
})
|
|
254
252
|
}
|
|
255
253
|
|
|
256
|
-
return
|
|
257
|
-
nodes: [and],
|
|
258
|
-
})
|
|
254
|
+
return and
|
|
259
255
|
}
|
|
260
256
|
|
|
261
257
|
/**
|
|
@@ -285,9 +281,9 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
285
281
|
|
|
286
282
|
if (schema.enum) {
|
|
287
283
|
return createUnionDeclaration({
|
|
288
|
-
nodes: schema.enum.map((name) => {
|
|
284
|
+
nodes: schema.enum.map((name: any) => {
|
|
289
285
|
return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))
|
|
290
|
-
})
|
|
286
|
+
}) as unknown as ArrayTwoOrMore<ts.TypeNode>,
|
|
291
287
|
})
|
|
292
288
|
}
|
|
293
289
|
|
|
@@ -309,7 +305,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
309
305
|
nodes: prefixItems.map((item) => {
|
|
310
306
|
// no baseType so we can fall back on an union when using enum
|
|
311
307
|
return this.getBaseTypeFromSchema(item, undefined)!
|
|
312
|
-
})
|
|
308
|
+
}) as ArrayTwoOrMore<ts.TypeNode>,
|
|
313
309
|
})
|
|
314
310
|
}
|
|
315
311
|
|
|
@@ -333,7 +329,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
333
329
|
baseName
|
|
334
330
|
)!,
|
|
335
331
|
nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,
|
|
336
|
-
].filter(Boolean) as ts.TypeNode
|
|
332
|
+
].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
337
333
|
})
|
|
338
334
|
}
|
|
339
335
|
// string, boolean, null, number
|
package/src/plugin.ts
CHANGED
|
@@ -111,7 +111,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
|
111
111
|
return this.addFile({
|
|
112
112
|
path,
|
|
113
113
|
fileName: `${this.resolveName({ name, pluginName })}.ts`,
|
|
114
|
-
source:
|
|
114
|
+
source: builder.print(name),
|
|
115
115
|
})
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -143,7 +143,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
|
143
143
|
await this.addFile({
|
|
144
144
|
path,
|
|
145
145
|
fileName: `${this.resolveName({ name: output, pluginName })}.ts`,
|
|
146
|
-
source:
|
|
146
|
+
source: builder.print(),
|
|
147
147
|
})
|
|
148
148
|
}
|
|
149
149
|
|