@kubb/swagger-ts 1.1.6 → 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 +13 -19
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -19
- package/package.json +30 -26
- package/src/builders/TypeBuilder.ts +5 -5
- package/src/generators/OperationGenerator.ts +7 -6
- package/src/generators/TypeGenerator.ts +25 -28
- package/src/plugin.ts +6 -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
|
@@ -4,18 +4,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var module$1 = require('module');
|
|
6
6
|
var pathParser = require('path');
|
|
7
|
-
var changeCase = require('change-case');
|
|
8
7
|
var core = require('@kubb/core');
|
|
9
8
|
var swagger = require('@kubb/swagger');
|
|
9
|
+
var changeCase = require('change-case');
|
|
10
10
|
var tsCodegen = require('@kubb/ts-codegen');
|
|
11
11
|
var ts = require('typescript');
|
|
12
|
-
var uniqueId = require('lodash.uniqueid');
|
|
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
16
|
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
18
|
-
var uniqueId__default = /*#__PURE__*/_interopDefault(uniqueId);
|
|
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)));
|
|
21
19
|
var __defProp = Object.defineProperty;
|
|
@@ -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,11 +1,10 @@
|
|
|
1
1
|
import { createRequire } from 'module';
|
|
2
2
|
import pathParser from 'node:path';
|
|
3
|
-
import {
|
|
4
|
-
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';
|
|
5
4
|
import { pluginName as pluginName$1, OasBuilder, ImportsGenerator, OperationGenerator as OperationGenerator$1, isReference } from '@kubb/swagger';
|
|
6
|
-
import {
|
|
5
|
+
import { pascalCase, pascalCaseTransformMerge, camelCase } from 'change-case';
|
|
6
|
+
import { print, createImportDeclaration, createTypeAliasDeclaration, modifiers, appendJSDocToNode, createUnionDeclaration, createPropertySignature, createIndexSignature, createIntersectionDeclaration, createEnumDeclaration, createTupleDeclaration } from '@kubb/ts-codegen';
|
|
7
7
|
import ts from 'typescript';
|
|
8
|
-
import uniqueId from 'lodash.uniqueid';
|
|
9
8
|
|
|
10
9
|
createRequire(import.meta.url);
|
|
11
10
|
var __defProp = Object.defineProperty;
|
|
@@ -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,32 +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
|
-
"
|
|
50
|
-
"tsup": "^6.7.0"
|
|
48
|
+
"eslint": "^8.42.0",
|
|
49
|
+
"tsup": "^6.7.0",
|
|
50
|
+
"@kubb/eslint-config": "0.1.0",
|
|
51
|
+
"@kubb/tsup-config": "0.1.0",
|
|
52
|
+
"@kubb/typescript-config": "0.1.0"
|
|
53
|
+
},
|
|
54
|
+
"packageManager": "pnpm@8.3.0",
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18",
|
|
57
|
+
"pnpm": ">=8.3.0"
|
|
51
58
|
},
|
|
52
59
|
"publishConfig": {
|
|
53
60
|
"access": "public",
|
|
54
61
|
"registry": "https://registry.npmjs.org/"
|
|
55
62
|
},
|
|
56
|
-
"engines": {
|
|
57
|
-
"node": ">=18",
|
|
58
|
-
"pnpm": ">=8"
|
|
59
|
-
},
|
|
60
63
|
"scripts": {
|
|
61
64
|
"build": "tsup",
|
|
62
|
-
"
|
|
65
|
+
"clean": "rimraf ./dist",
|
|
66
|
+
"lint": "eslint \"**/*.{ts,tsx}\"",
|
|
67
|
+
"lint-fix": "eslint \"**/*.{ts,tsx}\" --quiet --fix",
|
|
63
68
|
"release": "pnpm publish --no-git-check",
|
|
64
|
-
"
|
|
65
|
-
"pre-push": "pnpm typecheck",
|
|
69
|
+
"start": "tsup --watch",
|
|
66
70
|
"test": "vitest --passWithNoTests",
|
|
67
|
-
"
|
|
68
|
-
"
|
|
71
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false",
|
|
72
|
+
"upgrade": "pnpm update"
|
|
69
73
|
}
|
|
70
74
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { FileResolver, Refs } from '@kubb/swagger'
|
|
2
|
-
import { OasBuilder, ImportsGenerator } from '@kubb/swagger'
|
|
3
|
-
import type { PluginContext } from '@kubb/core'
|
|
4
1
|
import { nameSorter } from '@kubb/core'
|
|
2
|
+
import { ImportsGenerator, OasBuilder } from '@kubb/swagger'
|
|
5
3
|
import { createImportDeclaration, print } from '@kubb/ts-codegen'
|
|
6
4
|
|
|
7
5
|
import { TypeGenerator } from '../generators/TypeGenerator.ts'
|
|
8
6
|
|
|
7
|
+
import type { PluginContext } from '@kubb/core'
|
|
8
|
+
import type { FileResolver, Refs } from '@kubb/swagger'
|
|
9
9
|
import type ts from 'typescript'
|
|
10
10
|
|
|
11
11
|
type Generated = { import: { refs: Refs; name: string }; sources: ts.Node[] }
|
|
@@ -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) => {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import type { File, PathMode, PluginContext } from '@kubb/core'
|
|
2
1
|
import { getRelativePath } from '@kubb/core'
|
|
3
2
|
import { OperationGenerator as Generator } from '@kubb/swagger'
|
|
4
|
-
import type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'
|
|
5
3
|
|
|
6
4
|
import { TypeBuilder } from '../builders/index.ts'
|
|
7
5
|
import { pluginName } from '../plugin.ts'
|
|
8
6
|
|
|
7
|
+
import type { File, PathMode, PluginContext } from '@kubb/core'
|
|
8
|
+
import type { FileResolver, Oas, Operation, OperationSchemas, Resolver } from '@kubb/swagger'
|
|
9
|
+
|
|
9
10
|
type Options = {
|
|
10
11
|
oas: Oas
|
|
11
12
|
resolvePath: PluginContext['resolvePath']
|
|
@@ -54,7 +55,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
54
55
|
return getRelativePath(root, resolvedTypeId)
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
const source =
|
|
58
|
+
const source = new TypeBuilder(oas)
|
|
58
59
|
.add(schemas.pathParams)
|
|
59
60
|
.add(schemas.queryParams)
|
|
60
61
|
.add(schemas.response)
|
|
@@ -86,7 +87,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
86
87
|
return getRelativePath(root, resolvedTypeId)
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
const source =
|
|
90
|
+
const source = new TypeBuilder(oas)
|
|
90
91
|
.add(schemas.pathParams)
|
|
91
92
|
.add(schemas.queryParams)
|
|
92
93
|
.add(schemas.request)
|
|
@@ -119,7 +120,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
119
120
|
return getRelativePath(root, resolvedTypeId)
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
const source =
|
|
123
|
+
const source = new TypeBuilder(oas)
|
|
123
124
|
.add(schemas.pathParams)
|
|
124
125
|
.add(schemas.queryParams)
|
|
125
126
|
.add(schemas.request)
|
|
@@ -152,7 +153,7 @@ export class OperationGenerator extends Generator<Options> {
|
|
|
152
153
|
return getRelativePath(root, resolvedTypeId)
|
|
153
154
|
}
|
|
154
155
|
|
|
155
|
-
const source =
|
|
156
|
+
const source = new TypeBuilder(oas)
|
|
156
157
|
.add(schemas.pathParams)
|
|
157
158
|
.add(schemas.request)
|
|
158
159
|
.add(schemas.queryParams)
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
|
-
import
|
|
3
|
-
import { pascalCase, camelCase } from 'change-case'
|
|
4
|
-
import uniqueId from 'lodash.uniqueid'
|
|
5
|
-
|
|
6
|
-
import type { PluginContext } from '@kubb/core'
|
|
7
|
-
import { getUniqueName, SchemaGenerator } from '@kubb/core'
|
|
8
|
-
import type { Oas, OpenAPIV3, Refs } from '@kubb/swagger'
|
|
2
|
+
import { getUniqueName, SchemaGenerator, uniqueId } from '@kubb/core'
|
|
9
3
|
import { isReference } from '@kubb/swagger'
|
|
10
4
|
import {
|
|
11
5
|
appendJSDocToNode,
|
|
@@ -16,11 +10,18 @@ import {
|
|
|
16
10
|
createTupleDeclaration,
|
|
17
11
|
createTypeAliasDeclaration,
|
|
18
12
|
createUnionDeclaration,
|
|
19
|
-
|
|
13
|
+
modifiers,
|
|
20
14
|
} from '@kubb/ts-codegen'
|
|
21
15
|
|
|
22
|
-
import {
|
|
16
|
+
import { camelCase, pascalCase } from 'change-case'
|
|
17
|
+
import ts from 'typescript'
|
|
18
|
+
|
|
23
19
|
import { pluginName } from '../plugin.ts'
|
|
20
|
+
import { keywordTypeNodes } from '../utils/index.ts'
|
|
21
|
+
|
|
22
|
+
import type { PluginContext } from '@kubb/core'
|
|
23
|
+
import type { Oas, OpenAPIV3, Refs } from '@kubb/swagger'
|
|
24
|
+
import type { ArrayTwoOrMore } from '@kubb/ts-codegen'
|
|
24
25
|
|
|
25
26
|
const { factory } = ts
|
|
26
27
|
|
|
@@ -59,7 +60,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
const node = createTypeAliasDeclaration({
|
|
62
|
-
modifiers: [
|
|
63
|
+
modifiers: [modifiers.export],
|
|
63
64
|
name: this.options.resolveName({ name: baseName, pluginName }) || baseName,
|
|
64
65
|
type,
|
|
65
66
|
})
|
|
@@ -211,22 +212,20 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
211
212
|
const union = factory.createParenthesizedType(
|
|
212
213
|
createUnionDeclaration({
|
|
213
214
|
nodes: schema.oneOf
|
|
214
|
-
.map((item) => {
|
|
215
|
-
return this.getBaseTypeFromSchema(item)
|
|
215
|
+
.map((item: any) => {
|
|
216
|
+
return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)
|
|
216
217
|
})
|
|
217
|
-
.filter(Boolean) as ts.TypeNode
|
|
218
|
+
.filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
218
219
|
})
|
|
219
220
|
)
|
|
220
221
|
|
|
221
222
|
if (schemaWithoutOneOf.properties) {
|
|
222
223
|
return createIntersectionDeclaration({
|
|
223
|
-
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ts.TypeNode
|
|
224
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutOneOf, baseName), union].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
224
225
|
})
|
|
225
226
|
}
|
|
226
227
|
|
|
227
|
-
return
|
|
228
|
-
nodes: [union],
|
|
229
|
-
})
|
|
228
|
+
return union
|
|
230
229
|
}
|
|
231
230
|
|
|
232
231
|
if (schema.anyOf) {
|
|
@@ -239,22 +238,20 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
239
238
|
const and = factory.createParenthesizedType(
|
|
240
239
|
factory.createIntersectionTypeNode(
|
|
241
240
|
schema.allOf
|
|
242
|
-
.map((item) => {
|
|
243
|
-
return this.getBaseTypeFromSchema(item)
|
|
241
|
+
.map((item: any) => {
|
|
242
|
+
return this.getBaseTypeFromSchema(item as OpenAPIV3.SchemaObject)
|
|
244
243
|
})
|
|
245
|
-
.filter(Boolean) as ts.TypeNode
|
|
244
|
+
.filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>
|
|
246
245
|
)
|
|
247
246
|
)
|
|
248
247
|
|
|
249
248
|
if (schemaWithoutAllOf.properties) {
|
|
250
249
|
return createIntersectionDeclaration({
|
|
251
|
-
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ts.TypeNode
|
|
250
|
+
nodes: [this.getBaseTypeFromSchema(schemaWithoutAllOf, baseName), and].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
252
251
|
})
|
|
253
252
|
}
|
|
254
253
|
|
|
255
|
-
return
|
|
256
|
-
nodes: [and],
|
|
257
|
-
})
|
|
254
|
+
return and
|
|
258
255
|
}
|
|
259
256
|
|
|
260
257
|
/**
|
|
@@ -284,9 +281,9 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
284
281
|
|
|
285
282
|
if (schema.enum) {
|
|
286
283
|
return createUnionDeclaration({
|
|
287
|
-
nodes: schema.enum.map((name) => {
|
|
284
|
+
nodes: schema.enum.map((name: any) => {
|
|
288
285
|
return factory.createLiteralTypeNode(typeof name === 'number' ? factory.createNumericLiteral(name) : factory.createStringLiteral(`${name}`))
|
|
289
|
-
})
|
|
286
|
+
}) as unknown as ArrayTwoOrMore<ts.TypeNode>,
|
|
290
287
|
})
|
|
291
288
|
}
|
|
292
289
|
|
|
@@ -308,7 +305,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
308
305
|
nodes: prefixItems.map((item) => {
|
|
309
306
|
// no baseType so we can fall back on an union when using enum
|
|
310
307
|
return this.getBaseTypeFromSchema(item, undefined)!
|
|
311
|
-
})
|
|
308
|
+
}) as ArrayTwoOrMore<ts.TypeNode>,
|
|
312
309
|
})
|
|
313
310
|
}
|
|
314
311
|
|
|
@@ -332,7 +329,7 @@ export class TypeGenerator extends SchemaGenerator<Options, OpenAPIV3.SchemaObje
|
|
|
332
329
|
baseName
|
|
333
330
|
)!,
|
|
334
331
|
nullable ? factory.createLiteralTypeNode(factory.createNull()) : undefined,
|
|
335
|
-
].filter(Boolean) as ts.TypeNode
|
|
332
|
+
].filter(Boolean) as ArrayTwoOrMore<ts.TypeNode>,
|
|
336
333
|
})
|
|
337
334
|
}
|
|
338
335
|
// string, boolean, null, number
|
package/src/plugin.ts
CHANGED
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
import pathParser from 'node:path'
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import { getRelativePath, createPlugin, getPathMode, validatePlugins, writeIndexes, renderTemplate } from '@kubb/core'
|
|
7
|
+
import { createPlugin, getPathMode, getRelativePath, renderTemplate, validatePlugins, writeIndexes } from '@kubb/core'
|
|
10
8
|
import { pluginName as swaggerPluginName } from '@kubb/swagger'
|
|
11
|
-
|
|
9
|
+
|
|
10
|
+
import { pascalCase, pascalCaseTransformMerge } from 'change-case'
|
|
12
11
|
|
|
13
12
|
import { TypeBuilder } from './builders/index.ts'
|
|
14
13
|
import { OperationGenerator } from './generators/index.ts'
|
|
15
14
|
|
|
15
|
+
import type { OpenAPIV3, API as SwaggerApi } from '@kubb/swagger'
|
|
16
16
|
import type { PluginOptions } from './types.ts'
|
|
17
17
|
|
|
18
18
|
export const pluginName = 'swagger-ts' as const
|
|
@@ -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
|
|