@kubb/swagger-ts 1.1.7 → 1.1.9
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 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -18
- package/package.json +27 -26
- package/src/builders/TypeBuilder.ts +2 -2
- package/src/generators/OperationGenerator.ts +4 -4
- package/src/generators/TypeGenerator.ts +18 -25
- package/src/plugin.ts +2 -6
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
|
@@ -2,22 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var module$1 = require('module');
|
|
6
5
|
var pathParser = require('path');
|
|
7
6
|
var core = require('@kubb/core');
|
|
8
7
|
var swagger = require('@kubb/swagger');
|
|
9
8
|
var changeCase = require('change-case');
|
|
10
9
|
var tsCodegen = require('@kubb/ts-codegen');
|
|
11
|
-
var uniqueId = require('lodash.uniqueid');
|
|
12
10
|
var ts = require('typescript');
|
|
13
11
|
|
|
14
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
13
|
|
|
16
14
|
var pathParser__default = /*#__PURE__*/_interopDefault(pathParser);
|
|
17
|
-
var uniqueId__default = /*#__PURE__*/_interopDefault(uniqueId);
|
|
18
15
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
19
16
|
|
|
20
|
-
module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href)));
|
|
21
17
|
var __defProp = Object.defineProperty;
|
|
22
18
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
23
19
|
var __publicField = (obj, key, value) => {
|
|
@@ -56,7 +52,7 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
56
52
|
return this.extraNodes;
|
|
57
53
|
}
|
|
58
54
|
const node = tsCodegen.createTypeAliasDeclaration({
|
|
59
|
-
modifiers: [tsCodegen.
|
|
55
|
+
modifiers: [tsCodegen.modifiers.export],
|
|
60
56
|
name: this.options.resolveName({ name: baseName, pluginName }) || baseName,
|
|
61
57
|
type
|
|
62
58
|
});
|
|
@@ -152,7 +148,7 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
152
148
|
ref = this.refs[$ref] = {
|
|
153
149
|
propertyName,
|
|
154
150
|
originalName,
|
|
155
|
-
name:
|
|
151
|
+
name: core.uniqueId(propertyName)
|
|
156
152
|
};
|
|
157
153
|
return factory2.createTypeReferenceNode(ref.name, void 0);
|
|
158
154
|
}
|
|
@@ -187,9 +183,7 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
187
183
|
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean)
|
|
188
184
|
});
|
|
189
185
|
}
|
|
190
|
-
return
|
|
191
|
-
nodes: [union]
|
|
192
|
-
});
|
|
186
|
+
return union;
|
|
193
187
|
}
|
|
194
188
|
if (schema.anyOf) ;
|
|
195
189
|
if (schema.allOf) {
|
|
@@ -206,9 +200,7 @@ var _TypeGenerator = class extends core.SchemaGenerator {
|
|
|
206
200
|
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean)
|
|
207
201
|
});
|
|
208
202
|
}
|
|
209
|
-
return
|
|
210
|
-
nodes: [and]
|
|
211
|
-
});
|
|
203
|
+
return and;
|
|
212
204
|
}
|
|
213
205
|
if (schema.enum && baseName) {
|
|
214
206
|
const enumName = core.getUniqueName(baseName, _TypeGenerator.usedEnumNames);
|
|
@@ -300,7 +292,7 @@ var TypeBuilder = class extends swagger.OasBuilder {
|
|
|
300
292
|
}
|
|
301
293
|
return this;
|
|
302
294
|
}
|
|
303
|
-
|
|
295
|
+
print(name) {
|
|
304
296
|
const codes = [];
|
|
305
297
|
const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(core.nameSorter).map((operationSchema) => {
|
|
306
298
|
const generator = new TypeGenerator(this.oas, {
|
|
@@ -322,7 +314,7 @@ var TypeBuilder = class extends swagger.OasBuilder {
|
|
|
322
314
|
});
|
|
323
315
|
if (this.config.withImports) {
|
|
324
316
|
const importsGenerator = new swagger.ImportsGenerator({ fileResolver: this.config.fileResolver });
|
|
325
|
-
const importMeta =
|
|
317
|
+
const importMeta = importsGenerator.build(generated.map((item) => item.import));
|
|
326
318
|
if (importMeta) {
|
|
327
319
|
const nodes = importMeta.map((item) => {
|
|
328
320
|
return tsCodegen.createImportDeclaration({
|
|
@@ -366,7 +358,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
366
358
|
});
|
|
367
359
|
return core.getRelativePath(root, resolvedTypeId);
|
|
368
360
|
};
|
|
369
|
-
const source =
|
|
361
|
+
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
362
|
return {
|
|
371
363
|
path: type.filePath,
|
|
372
364
|
fileName: type.fileName,
|
|
@@ -384,7 +376,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
384
376
|
});
|
|
385
377
|
return core.getRelativePath(root, resolvedTypeId);
|
|
386
378
|
};
|
|
387
|
-
const source =
|
|
379
|
+
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
380
|
return {
|
|
389
381
|
path: type.filePath,
|
|
390
382
|
fileName: type.fileName,
|
|
@@ -402,7 +394,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
402
394
|
});
|
|
403
395
|
return core.getRelativePath(root, resolvedTypeId);
|
|
404
396
|
};
|
|
405
|
-
const source =
|
|
397
|
+
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
398
|
return {
|
|
407
399
|
path: type.filePath,
|
|
408
400
|
fileName: type.fileName,
|
|
@@ -420,7 +412,7 @@ var OperationGenerator = class extends swagger.OperationGenerator {
|
|
|
420
412
|
});
|
|
421
413
|
return core.getRelativePath(root, resolvedTypeId);
|
|
422
414
|
};
|
|
423
|
-
const source =
|
|
415
|
+
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
416
|
return {
|
|
425
417
|
path: type.filePath,
|
|
426
418
|
fileName: type.fileName,
|
|
@@ -499,7 +491,7 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
499
491
|
return this.addFile({
|
|
500
492
|
path,
|
|
501
493
|
fileName: `${this.resolveName({ name, pluginName })}.ts`,
|
|
502
|
-
source:
|
|
494
|
+
source: builder.print(name)
|
|
503
495
|
});
|
|
504
496
|
};
|
|
505
497
|
const promises = Object.entries(schemas).map(mapFolderSchema);
|
|
@@ -524,7 +516,7 @@ var definePlugin = core.createPlugin((options) => {
|
|
|
524
516
|
await this.addFile({
|
|
525
517
|
path,
|
|
526
518
|
fileName: `${this.resolveName({ name: output, pluginName })}.ts`,
|
|
527
|
-
source:
|
|
519
|
+
source: builder.print()
|
|
528
520
|
});
|
|
529
521
|
}
|
|
530
522
|
const operationGenerator = new OperationGenerator({
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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);
|
|
10
|
+
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
12
12
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
13
|
var __publicField = (obj, key, value) => {
|
|
@@ -46,7 +46,7 @@ var _TypeGenerator = class extends SchemaGenerator {
|
|
|
46
46
|
return this.extraNodes;
|
|
47
47
|
}
|
|
48
48
|
const node = createTypeAliasDeclaration({
|
|
49
|
-
modifiers: [
|
|
49
|
+
modifiers: [modifiers.export],
|
|
50
50
|
name: this.options.resolveName({ name: baseName, pluginName }) || baseName,
|
|
51
51
|
type
|
|
52
52
|
});
|
|
@@ -177,9 +177,7 @@ var _TypeGenerator = class extends SchemaGenerator {
|
|
|
177
177
|
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean)
|
|
178
178
|
});
|
|
179
179
|
}
|
|
180
|
-
return
|
|
181
|
-
nodes: [union]
|
|
182
|
-
});
|
|
180
|
+
return union;
|
|
183
181
|
}
|
|
184
182
|
if (schema.anyOf) ;
|
|
185
183
|
if (schema.allOf) {
|
|
@@ -196,9 +194,7 @@ var _TypeGenerator = class extends SchemaGenerator {
|
|
|
196
194
|
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean)
|
|
197
195
|
});
|
|
198
196
|
}
|
|
199
|
-
return
|
|
200
|
-
nodes: [and]
|
|
201
|
-
});
|
|
197
|
+
return and;
|
|
202
198
|
}
|
|
203
199
|
if (schema.enum && baseName) {
|
|
204
200
|
const enumName = getUniqueName(baseName, _TypeGenerator.usedEnumNames);
|
|
@@ -290,7 +286,7 @@ var TypeBuilder = class extends OasBuilder {
|
|
|
290
286
|
}
|
|
291
287
|
return this;
|
|
292
288
|
}
|
|
293
|
-
|
|
289
|
+
print(name) {
|
|
294
290
|
const codes = [];
|
|
295
291
|
const generated = this.items.filter((operationSchema) => name ? operationSchema.name === name : true).sort(nameSorter).map((operationSchema) => {
|
|
296
292
|
const generator = new TypeGenerator(this.oas, {
|
|
@@ -312,7 +308,7 @@ var TypeBuilder = class extends OasBuilder {
|
|
|
312
308
|
});
|
|
313
309
|
if (this.config.withImports) {
|
|
314
310
|
const importsGenerator = new ImportsGenerator({ fileResolver: this.config.fileResolver });
|
|
315
|
-
const importMeta =
|
|
311
|
+
const importMeta = importsGenerator.build(generated.map((item) => item.import));
|
|
316
312
|
if (importMeta) {
|
|
317
313
|
const nodes = importMeta.map((item) => {
|
|
318
314
|
return createImportDeclaration({
|
|
@@ -356,7 +352,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
356
352
|
});
|
|
357
353
|
return getRelativePath(root, resolvedTypeId);
|
|
358
354
|
};
|
|
359
|
-
const source =
|
|
355
|
+
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
356
|
return {
|
|
361
357
|
path: type.filePath,
|
|
362
358
|
fileName: type.fileName,
|
|
@@ -374,7 +370,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
374
370
|
});
|
|
375
371
|
return getRelativePath(root, resolvedTypeId);
|
|
376
372
|
};
|
|
377
|
-
const source =
|
|
373
|
+
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
374
|
return {
|
|
379
375
|
path: type.filePath,
|
|
380
376
|
fileName: type.fileName,
|
|
@@ -392,7 +388,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
392
388
|
});
|
|
393
389
|
return getRelativePath(root, resolvedTypeId);
|
|
394
390
|
};
|
|
395
|
-
const source =
|
|
391
|
+
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
392
|
return {
|
|
397
393
|
path: type.filePath,
|
|
398
394
|
fileName: type.fileName,
|
|
@@ -410,7 +406,7 @@ var OperationGenerator = class extends OperationGenerator$1 {
|
|
|
410
406
|
});
|
|
411
407
|
return getRelativePath(root, resolvedTypeId);
|
|
412
408
|
};
|
|
413
|
-
const source =
|
|
409
|
+
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
410
|
return {
|
|
415
411
|
path: type.filePath,
|
|
416
412
|
fileName: type.fileName,
|
|
@@ -489,7 +485,7 @@ var definePlugin = createPlugin((options) => {
|
|
|
489
485
|
return this.addFile({
|
|
490
486
|
path,
|
|
491
487
|
fileName: `${this.resolveName({ name, pluginName })}.ts`,
|
|
492
|
-
source:
|
|
488
|
+
source: builder.print(name)
|
|
493
489
|
});
|
|
494
490
|
};
|
|
495
491
|
const promises = Object.entries(schemas).map(mapFolderSchema);
|
|
@@ -514,7 +510,7 @@ var definePlugin = createPlugin((options) => {
|
|
|
514
510
|
await this.addFile({
|
|
515
511
|
path,
|
|
516
512
|
fileName: `${this.resolveName({ name: output, pluginName })}.ts`,
|
|
517
|
-
source:
|
|
513
|
+
source: builder.print()
|
|
518
514
|
});
|
|
519
515
|
}
|
|
520
516
|
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.9",
|
|
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.9",
|
|
44
|
+
"@kubb/swagger": "1.1.9",
|
|
45
|
+
"@kubb/ts-codegen": "1.1.9"
|
|
47
46
|
},
|
|
48
47
|
"devDependencies": {
|
|
49
48
|
"eslint": "^8.42.0",
|
|
50
49
|
"tsup": "^6.7.0",
|
|
51
|
-
"@
|
|
52
|
-
"@kubb/
|
|
53
|
-
"@kubb/
|
|
50
|
+
"@kubb/eslint-config": "1.1.8",
|
|
51
|
+
"@kubb/ts-config": "0.1.0",
|
|
52
|
+
"@kubb/tsup-config": "1.1.8"
|
|
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,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { getUniqueName, SchemaGenerator } from '@kubb/core'
|
|
1
|
+
import { getUniqueName, SchemaGenerator, uniqueId } from '@kubb/core'
|
|
3
2
|
import { isReference } from '@kubb/swagger'
|
|
4
3
|
import {
|
|
5
4
|
appendJSDocToNode,
|
|
@@ -10,11 +9,10 @@ import {
|
|
|
10
9
|
createTupleDeclaration,
|
|
11
10
|
createTypeAliasDeclaration,
|
|
12
11
|
createUnionDeclaration,
|
|
13
|
-
|
|
12
|
+
modifiers,
|
|
14
13
|
} from '@kubb/ts-codegen'
|
|
15
14
|
|
|
16
15
|
import { camelCase, pascalCase } from 'change-case'
|
|
17
|
-
import uniqueId from 'lodash.uniqueid'
|
|
18
16
|
import ts from 'typescript'
|
|
19
17
|
|
|
20
18
|
import { pluginName } from '../plugin.ts'
|
|
@@ -22,6 +20,7 @@ import { keywordTypeNodes } from '../utils/index.ts'
|
|
|
22
20
|
|
|
23
21
|
import type { PluginContext } from '@kubb/core'
|
|
24
22
|
import type { Oas, OpenAPIV3, Refs } from '@kubb/swagger'
|
|
23
|
+
import type { ArrayTwoOrMore } from '@kubb/ts-codegen'
|
|
25
24
|
|
|
26
25
|
const { factory } = ts
|
|
27
26
|
|
|
@@ -60,7 +59,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
const node = createTypeAliasDeclaration({
|
|
63
|
-
modifiers: [
|
|
62
|
+
modifiers: [modifiers.export],
|
|
64
63
|
name: this.options.resolveName({ name: baseName, pluginName }) || baseName,
|
|
65
64
|
type,
|
|
66
65
|
})
|
|
@@ -173,7 +172,6 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
173
172
|
const propertyName = this.options.resolveName({ name: originalName, pluginName }) || originalName
|
|
174
173
|
|
|
175
174
|
if (originalName === baseName) {
|
|
176
|
-
// eslint-disable-next-line no-multi-assign
|
|
177
175
|
ref = this.refs[$ref] = {
|
|
178
176
|
propertyName,
|
|
179
177
|
originalName,
|
|
@@ -183,7 +181,6 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
183
181
|
return factory.createTypeReferenceNode(ref.name!, undefined)
|
|
184
182
|
}
|
|
185
183
|
|
|
186
|
-
// eslint-disable-next-line no-multi-assign
|
|
187
184
|
ref = this.refs[$ref] = {
|
|
188
185
|
propertyName,
|
|
189
186
|
originalName,
|
|
@@ -212,22 +209,20 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
212
209
|
const union = factory.createParenthesizedType(
|
|
213
210
|
createUnionDeclaration({
|
|
214
211
|
nodes: schema.oneOf
|
|
215
|
-
.map((item) => {
|
|
216
|
-
return this.getBaseTypeFromSchema(item)
|
|
212
|
+
.map((item: any) => {
|
|
213
|
+
return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)
|
|
217
214
|
})
|
|
218
|
-
.filter(Boolean) as ts.TypeNode
|
|
215
|
+
.filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
219
216
|
})
|
|
220
217
|
)
|
|
221
218
|
|
|
222
219
|
if (schemaWithoutOneOf.properties) {
|
|
223
220
|
return createIntersectionDeclaration({
|
|
224
|
-
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ts.TypeNode
|
|
221
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
225
222
|
})
|
|
226
223
|
}
|
|
227
224
|
|
|
228
|
-
return
|
|
229
|
-
nodes: [union],
|
|
230
|
-
})
|
|
225
|
+
return union
|
|
231
226
|
}
|
|
232
227
|
|
|
233
228
|
if (schema.anyOf) {
|
|
@@ -240,22 +235,20 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
240
235
|
const and = factory.createParenthesizedType(
|
|
241
236
|
factory.createIntersectionTypeNode(
|
|
242
237
|
schema.allOf
|
|
243
|
-
.map((item) => {
|
|
244
|
-
return this.getBaseTypeFromSchema(item)
|
|
238
|
+
.map((item: any) => {
|
|
239
|
+
return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)
|
|
245
240
|
})
|
|
246
|
-
.filter(Boolean) as ts.TypeNode
|
|
241
|
+
.filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>
|
|
247
242
|
)
|
|
248
243
|
)
|
|
249
244
|
|
|
250
245
|
if (schemaWithoutAllOf.properties) {
|
|
251
246
|
return createIntersectionDeclaration({
|
|
252
|
-
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ts.TypeNode
|
|
247
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
253
248
|
})
|
|
254
249
|
}
|
|
255
250
|
|
|
256
|
-
return
|
|
257
|
-
nodes: [and],
|
|
258
|
-
})
|
|
251
|
+
return and
|
|
259
252
|
}
|
|
260
253
|
|
|
261
254
|
/**
|
|
@@ -285,9 +278,9 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
285
278
|
|
|
286
279
|
if (schema.enum) {
|
|
287
280
|
return createUnionDeclaration({
|
|
288
|
-
nodes: schema.enum.map((name) => {
|
|
281
|
+
nodes: schema.enum.map((name: any) => {
|
|
289
282
|
return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))
|
|
290
|
-
})
|
|
283
|
+
}) as unknown as ArrayTwoOrMore<ts.TypeNode>,
|
|
291
284
|
})
|
|
292
285
|
}
|
|
293
286
|
|
|
@@ -309,7 +302,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
309
302
|
nodes: prefixItems.map((item) => {
|
|
310
303
|
// no baseType so we can fall back on an union when using enum
|
|
311
304
|
return this.getBaseTypeFromSchema(item, undefined)!
|
|
312
|
-
})
|
|
305
|
+
}) as ArrayTwoOrMore<ts.TypeNode>,
|
|
313
306
|
})
|
|
314
307
|
}
|
|
315
308
|
|
|
@@ -333,7 +326,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
333
326
|
baseName
|
|
334
327
|
)!,
|
|
335
328
|
nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,
|
|
336
|
-
].filter(Boolean) as ts.TypeNode
|
|
329
|
+
].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
337
330
|
})
|
|
338
331
|
}
|
|
339
332
|
// string, boolean, null, number
|
package/src/plugin.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
-
/* eslint-disable no-console */
|
|
4
|
-
|
|
5
1
|
import pathParser from 'node:path'
|
|
6
2
|
|
|
7
3
|
import { createPlugin, getPathMode, getRelativePath, renderTemplate, validatePlugins, writeIndexes } from '@kubb/core'
|
|
@@ -111,7 +107,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
|
111
107
|
return this.addFile({
|
|
112
108
|
path,
|
|
113
109
|
fileName: `${this.resolveName({ name, pluginName })}.ts`,
|
|
114
|
-
source:
|
|
110
|
+
source: builder.print(name),
|
|
115
111
|
})
|
|
116
112
|
}
|
|
117
113
|
|
|
@@ -143,7 +139,7 @@ export const definePlugin = createPlugin<PluginOptions>((options) => {
|
|
|
143
139
|
await this.addFile({
|
|
144
140
|
path,
|
|
145
141
|
fileName: `${this.resolveName({ name: output, pluginName })}.ts`,
|
|
146
|
-
source:
|
|
142
|
+
source: builder.print(),
|
|
147
143
|
})
|
|
148
144
|
}
|
|
149
145
|
|