@kubb/plugin-ts 0.0.0-canary-20241104172400
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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/chunk-HJ6SFXKJ.js +306 -0
- package/dist/chunk-HJ6SFXKJ.js.map +1 -0
- package/dist/chunk-HZ6BGJL7.js +2539 -0
- package/dist/chunk-HZ6BGJL7.js.map +1 -0
- package/dist/chunk-PTC7IOBI.cjs +335 -0
- package/dist/chunk-PTC7IOBI.cjs.map +1 -0
- package/dist/chunk-RORQTUX5.cjs +2566 -0
- package/dist/chunk-RORQTUX5.cjs.map +1 -0
- package/dist/components.cjs +16 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +30 -0
- package/dist/components.d.ts +30 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +17 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types-zQCmVvxv.d.cts +97 -0
- package/dist/types-zQCmVvxv.d.ts +97 -0
- package/package.json +97 -0
- package/src/components/OasType.tsx +29 -0
- package/src/components/Type.tsx +141 -0
- package/src/components/index.ts +2 -0
- package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +6 -0
- package/src/generators/__snapshots__/catTypeAsConst.ts +11 -0
- package/src/generators/__snapshots__/createPet.ts +34 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +34 -0
- package/src/generators/__snapshots__/deletePet.ts +7 -0
- package/src/generators/__snapshots__/dogTypeAsConst.ts +11 -0
- package/src/generators/__snapshots__/enumAllOf.ts +10 -0
- package/src/generators/__snapshots__/enumArray.ts +19 -0
- package/src/generators/__snapshots__/enumInObject.ts +13 -0
- package/src/generators/__snapshots__/enumItems.ts +8 -0
- package/src/generators/__snapshots__/enumNames.ts +6 -0
- package/src/generators/__snapshots__/enumNamesConst.ts +6 -0
- package/src/generators/__snapshots__/enumNamesLiteral.ts +3 -0
- package/src/generators/__snapshots__/enumNamesPascalConst.ts +8 -0
- package/src/generators/__snapshots__/enumNamesType.ts +8 -0
- package/src/generators/__snapshots__/enumNullableMember.ts +8 -0
- package/src/generators/__snapshots__/enumNullableType.ts +8 -0
- package/src/generators/__snapshots__/enumString.ts +10 -0
- package/src/generators/__snapshots__/enumVarNamesType.ts +8 -0
- package/src/generators/__snapshots__/getPets.ts +26 -0
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +9 -0
- package/src/generators/__snapshots__/nullConstNull.ts +7 -0
- package/src/generators/__snapshots__/numberValueConst.ts +9 -0
- package/src/generators/__snapshots__/petMapper.ts +15 -0
- package/src/generators/__snapshots__/petQuestionToken.ts +19 -0
- package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +19 -0
- package/src/generators/__snapshots__/petUndefined.ts +19 -0
- package/src/generators/__snapshots__/pets.ts +14 -0
- package/src/generators/__snapshots__/petsStoreAdvancedDiscriminator.ts +31 -0
- package/src/generators/__snapshots__/petsStoreDiscriminator.ts +13 -0
- package/src/generators/__snapshots__/petsStoreRef.ts +1 -0
- package/src/generators/__snapshots__/plainDateDate.ts +1 -0
- package/src/generators/__snapshots__/plainDateString.ts +1 -0
- package/src/generators/__snapshots__/plainEmail.ts +1 -0
- package/src/generators/__snapshots__/plainFile.ts +1 -0
- package/src/generators/__snapshots__/plainTimeDate.ts +1 -0
- package/src/generators/__snapshots__/plainUuid.ts +1 -0
- package/src/generators/__snapshots__/readOnly.ts +20 -0
- package/src/generators/__snapshots__/showPetById.ts +31 -0
- package/src/generators/__snapshots__/stringValueConst.ts +9 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/oasGenerator.tsx +29 -0
- package/src/generators/typeGenerator.tsx +205 -0
- package/src/index.ts +2 -0
- package/src/parser/index.ts +279 -0
- package/src/plugin.ts +127 -0
- package/src/types.ts +97 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkPTC7IOBI_cjs = require('./chunk-PTC7IOBI.cjs');
|
|
4
|
+
require('./chunk-RORQTUX5.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "pluginTs", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkPTC7IOBI_cjs.pluginTs; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "pluginTsName", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkPTC7IOBI_cjs.pluginTsName; }
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
17
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { O as Options, P as PluginTs } from './types-zQCmVvxv.cjs';
|
|
3
|
+
import '@kubb/plugin-oas';
|
|
4
|
+
import 'typescript';
|
|
5
|
+
|
|
6
|
+
declare const pluginTsName = "plugin-ts";
|
|
7
|
+
declare const pluginTs: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginTs>;
|
|
8
|
+
|
|
9
|
+
export { PluginTs, pluginTs, pluginTsName };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as _kubb_core from '@kubb/core';
|
|
2
|
+
import { O as Options, P as PluginTs } from './types-zQCmVvxv.js';
|
|
3
|
+
import '@kubb/plugin-oas';
|
|
4
|
+
import 'typescript';
|
|
5
|
+
|
|
6
|
+
declare const pluginTsName = "plugin-ts";
|
|
7
|
+
declare const pluginTs: (options?: Options | undefined) => _kubb_core.UserPluginWithLifeCycle<PluginTs>;
|
|
8
|
+
|
|
9
|
+
export { PluginTs, pluginTs, pluginTsName };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* Specify the export location for the files and define the behavior of the output
|
|
8
|
+
* @default { path: 'types', barrelType: 'named' }
|
|
9
|
+
*/
|
|
10
|
+
output?: Output;
|
|
11
|
+
/**
|
|
12
|
+
* Group the clients based on the provided name.
|
|
13
|
+
*/
|
|
14
|
+
group?: Group;
|
|
15
|
+
/**
|
|
16
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
17
|
+
*/
|
|
18
|
+
exclude?: Array<Exclude>;
|
|
19
|
+
/**
|
|
20
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
21
|
+
*/
|
|
22
|
+
include?: Array<Include>;
|
|
23
|
+
/**
|
|
24
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
25
|
+
*/
|
|
26
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
27
|
+
/**
|
|
28
|
+
* Choose to use `enum` or `as const` for enums
|
|
29
|
+
* @default 'asConst'
|
|
30
|
+
* asPascalConst is deprecated
|
|
31
|
+
*/
|
|
32
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
33
|
+
/**
|
|
34
|
+
* Set a suffix for the generated enums.
|
|
35
|
+
* @default 'enum'
|
|
36
|
+
*/
|
|
37
|
+
enumSuffix?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
40
|
+
* @default 'string'
|
|
41
|
+
*/
|
|
42
|
+
dateType?: 'string' | 'date';
|
|
43
|
+
/**
|
|
44
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
45
|
+
* @default 'any'
|
|
46
|
+
*/
|
|
47
|
+
unknownType?: 'any' | 'unknown';
|
|
48
|
+
/**
|
|
49
|
+
* Choose what to use as mode for an optional value.
|
|
50
|
+
* @examples 'questionToken': type?: string
|
|
51
|
+
* @examples 'undefined': type: string | undefined
|
|
52
|
+
* @examples 'questionTokenAndUndefined': type?: string | undefined
|
|
53
|
+
* @default 'questionToken'
|
|
54
|
+
*/
|
|
55
|
+
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
|
56
|
+
transformers?: {
|
|
57
|
+
/**
|
|
58
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
59
|
+
*/
|
|
60
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
|
|
64
|
+
*/
|
|
65
|
+
oasType?: 'infer' | false;
|
|
66
|
+
/**
|
|
67
|
+
* @example
|
|
68
|
+
* Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
|
|
69
|
+
* category: factory.createPropertySignature(
|
|
70
|
+
* undefined,
|
|
71
|
+
* factory.createIdentifier("category"),
|
|
72
|
+
* factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
73
|
+
* factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
74
|
+
* )
|
|
75
|
+
*/
|
|
76
|
+
mapper?: Record<string, ts.PropertySignature>;
|
|
77
|
+
/**
|
|
78
|
+
* Define some generators next to the ts generators
|
|
79
|
+
*/
|
|
80
|
+
generators?: Array<Generator<PluginTs>>;
|
|
81
|
+
};
|
|
82
|
+
type ResolvedOptions = {
|
|
83
|
+
output: Output;
|
|
84
|
+
override: NonNullable<Options['override']>;
|
|
85
|
+
enumType: NonNullable<Options['enumType']>;
|
|
86
|
+
enumSuffix: NonNullable<Options['enumSuffix']>;
|
|
87
|
+
dateType: NonNullable<Options['dateType']>;
|
|
88
|
+
unknownType: NonNullable<Options['unknownType']>;
|
|
89
|
+
optionalType: NonNullable<Options['optionalType']>;
|
|
90
|
+
transformers: NonNullable<Options['transformers']>;
|
|
91
|
+
oasType: NonNullable<Options['oasType']>;
|
|
92
|
+
usedEnumNames: Record<string, number>;
|
|
93
|
+
mapper: Record<string, any>;
|
|
94
|
+
};
|
|
95
|
+
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
96
|
+
|
|
97
|
+
export type { Options as O, PluginTs as P };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
+
import { ResolvePathOptions, Exclude, Include, Override, Generator } from '@kubb/plugin-oas';
|
|
3
|
+
import ts from 'typescript';
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
/**
|
|
7
|
+
* Specify the export location for the files and define the behavior of the output
|
|
8
|
+
* @default { path: 'types', barrelType: 'named' }
|
|
9
|
+
*/
|
|
10
|
+
output?: Output;
|
|
11
|
+
/**
|
|
12
|
+
* Group the clients based on the provided name.
|
|
13
|
+
*/
|
|
14
|
+
group?: Group;
|
|
15
|
+
/**
|
|
16
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
17
|
+
*/
|
|
18
|
+
exclude?: Array<Exclude>;
|
|
19
|
+
/**
|
|
20
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
21
|
+
*/
|
|
22
|
+
include?: Array<Include>;
|
|
23
|
+
/**
|
|
24
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
25
|
+
*/
|
|
26
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
27
|
+
/**
|
|
28
|
+
* Choose to use `enum` or `as const` for enums
|
|
29
|
+
* @default 'asConst'
|
|
30
|
+
* asPascalConst is deprecated
|
|
31
|
+
*/
|
|
32
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
33
|
+
/**
|
|
34
|
+
* Set a suffix for the generated enums.
|
|
35
|
+
* @default 'enum'
|
|
36
|
+
*/
|
|
37
|
+
enumSuffix?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Choose to use `date` or `datetime` as JavaScript `Date` instead of `string`.
|
|
40
|
+
* @default 'string'
|
|
41
|
+
*/
|
|
42
|
+
dateType?: 'string' | 'date';
|
|
43
|
+
/**
|
|
44
|
+
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
45
|
+
* @default 'any'
|
|
46
|
+
*/
|
|
47
|
+
unknownType?: 'any' | 'unknown';
|
|
48
|
+
/**
|
|
49
|
+
* Choose what to use as mode for an optional value.
|
|
50
|
+
* @examples 'questionToken': type?: string
|
|
51
|
+
* @examples 'undefined': type: string | undefined
|
|
52
|
+
* @examples 'questionTokenAndUndefined': type?: string | undefined
|
|
53
|
+
* @default 'questionToken'
|
|
54
|
+
*/
|
|
55
|
+
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
|
56
|
+
transformers?: {
|
|
57
|
+
/**
|
|
58
|
+
* Customize the names based on the type that is provided by the plugin.
|
|
59
|
+
*/
|
|
60
|
+
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Export an Oas object as Oas type with `import type { Infer } from '@kubb/oas'`
|
|
64
|
+
*/
|
|
65
|
+
oasType?: 'infer' | false;
|
|
66
|
+
/**
|
|
67
|
+
* @example
|
|
68
|
+
* Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
|
|
69
|
+
* category: factory.createPropertySignature(
|
|
70
|
+
* undefined,
|
|
71
|
+
* factory.createIdentifier("category"),
|
|
72
|
+
* factory.createToken(ts.SyntaxKind.QuestionToken),
|
|
73
|
+
* factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
|
|
74
|
+
* )
|
|
75
|
+
*/
|
|
76
|
+
mapper?: Record<string, ts.PropertySignature>;
|
|
77
|
+
/**
|
|
78
|
+
* Define some generators next to the ts generators
|
|
79
|
+
*/
|
|
80
|
+
generators?: Array<Generator<PluginTs>>;
|
|
81
|
+
};
|
|
82
|
+
type ResolvedOptions = {
|
|
83
|
+
output: Output;
|
|
84
|
+
override: NonNullable<Options['override']>;
|
|
85
|
+
enumType: NonNullable<Options['enumType']>;
|
|
86
|
+
enumSuffix: NonNullable<Options['enumSuffix']>;
|
|
87
|
+
dateType: NonNullable<Options['dateType']>;
|
|
88
|
+
unknownType: NonNullable<Options['unknownType']>;
|
|
89
|
+
optionalType: NonNullable<Options['optionalType']>;
|
|
90
|
+
transformers: NonNullable<Options['transformers']>;
|
|
91
|
+
oasType: NonNullable<Options['oasType']>;
|
|
92
|
+
usedEnumNames: Record<string, number>;
|
|
93
|
+
mapper: Record<string, any>;
|
|
94
|
+
};
|
|
95
|
+
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
96
|
+
|
|
97
|
+
export type { Options as O, PluginTs as P };
|
package/package.json
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kubb/plugin-ts",
|
|
3
|
+
"version": "0.0.0-canary-20241104172400",
|
|
4
|
+
"description": "Generator plugin-ts",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"zod",
|
|
7
|
+
"plugins",
|
|
8
|
+
"kubb",
|
|
9
|
+
"codegen",
|
|
10
|
+
"swagger",
|
|
11
|
+
"openapi"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git://github.com/kubb-labs/kubb.git",
|
|
16
|
+
"directory": "packages/plugin-ts"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.cjs",
|
|
26
|
+
"default": "./dist/index.cjs"
|
|
27
|
+
},
|
|
28
|
+
"./generators": {
|
|
29
|
+
"import": "./dist/generators.js",
|
|
30
|
+
"require": "./dist/generators.cjs",
|
|
31
|
+
"default": "./dist/generators.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./components": {
|
|
34
|
+
"import": "./dist/components.js",
|
|
35
|
+
"require": "./dist/components.cjs",
|
|
36
|
+
"default": "./dist/components.cjs"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json",
|
|
39
|
+
"./*": "./*"
|
|
40
|
+
},
|
|
41
|
+
"main": "dist/index.cjs",
|
|
42
|
+
"module": "dist/index.js",
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"typesVersions": {
|
|
45
|
+
"*": {
|
|
46
|
+
"components": [
|
|
47
|
+
"./dist/components.d.ts"
|
|
48
|
+
],
|
|
49
|
+
"generators": [
|
|
50
|
+
"./dist/generators.d.ts"
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"src",
|
|
56
|
+
"dist",
|
|
57
|
+
"!/**/**.test.**",
|
|
58
|
+
"!/**/__tests__/**"
|
|
59
|
+
],
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@kubb/core": "0.0.0-canary-20241104172400",
|
|
62
|
+
"@kubb/fs": "0.0.0-canary-20241104172400",
|
|
63
|
+
"@kubb/oas": "0.0.0-canary-20241104172400",
|
|
64
|
+
"@kubb/parser-ts": "0.0.0-canary-20241104172400",
|
|
65
|
+
"@kubb/plugin-oas": "0.0.0-canary-20241104172400",
|
|
66
|
+
"@kubb/react": "0.0.0-canary-20241104172400"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/react": "^18.3.12",
|
|
70
|
+
"react": "^18.3.1",
|
|
71
|
+
"tsup": "^8.3.5",
|
|
72
|
+
"typescript": "^5.6.3",
|
|
73
|
+
"@kubb/config-ts": "0.0.0-canary-20241104172400",
|
|
74
|
+
"@kubb/config-tsup": "0.0.0-canary-20241104172400"
|
|
75
|
+
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"@kubb/react": "0.0.0-canary-20241104172400"
|
|
78
|
+
},
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=20"
|
|
81
|
+
},
|
|
82
|
+
"publishConfig": {
|
|
83
|
+
"access": "public",
|
|
84
|
+
"registry": "https://registry.npmjs.org/"
|
|
85
|
+
},
|
|
86
|
+
"scripts": {
|
|
87
|
+
"build": "tsup",
|
|
88
|
+
"clean": "npx rimraf ./dist",
|
|
89
|
+
"lint": "bun biome lint .",
|
|
90
|
+
"lint:fix": "bun biome lint --apply-unsafe .",
|
|
91
|
+
"release": "pnpm publish --no-git-check",
|
|
92
|
+
"release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
|
|
93
|
+
"start": "tsup --watch",
|
|
94
|
+
"test": "vitest --passWithNoTests",
|
|
95
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { File, Type } from '@kubb/react'
|
|
2
|
+
|
|
3
|
+
import type { OasTypes } from '@kubb/oas'
|
|
4
|
+
import type { ReactNode } from 'react'
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
/**
|
|
8
|
+
* Name of the function
|
|
9
|
+
*/
|
|
10
|
+
name: string
|
|
11
|
+
typeName: string
|
|
12
|
+
api: OasTypes.OASDocument
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function OasType({ name, typeName, api }: Props): ReactNode {
|
|
16
|
+
return (
|
|
17
|
+
<>
|
|
18
|
+
<File.Source name={name} isExportable isIndexable>
|
|
19
|
+
{`export const ${name} = ${JSON.stringify(api, undefined, 2)} as const`}
|
|
20
|
+
</File.Source>
|
|
21
|
+
<br />
|
|
22
|
+
<File.Source name={typeName} isExportable isIndexable isTypeOnly>
|
|
23
|
+
<Type name={typeName} export>
|
|
24
|
+
{`Infer<typeof ${name}>`}
|
|
25
|
+
</Type>
|
|
26
|
+
</File.Source>
|
|
27
|
+
</>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { File } from '@kubb/react'
|
|
2
|
+
|
|
3
|
+
import transformers from '@kubb/core/transformers'
|
|
4
|
+
import { print } from '@kubb/parser-ts'
|
|
5
|
+
import * as factory from '@kubb/parser-ts/factory'
|
|
6
|
+
import { type Schema, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
7
|
+
import { Fragment, type ReactNode } from 'react'
|
|
8
|
+
import type ts from 'typescript'
|
|
9
|
+
import { parse, typeKeywordMapper } from '../parser/index.ts'
|
|
10
|
+
import type { PluginTs } from '../types.ts'
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
name: string
|
|
14
|
+
typedName: string
|
|
15
|
+
tree: Array<Schema>
|
|
16
|
+
optionalType: PluginTs['resolvedOptions']['optionalType']
|
|
17
|
+
enumType: PluginTs['resolvedOptions']['enumType']
|
|
18
|
+
mapper: PluginTs['resolvedOptions']['mapper']
|
|
19
|
+
description?: string
|
|
20
|
+
keysToOmit?: string[]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function Type({ name, typedName, tree, keysToOmit, optionalType, enumType, mapper, description }: Props): ReactNode {
|
|
24
|
+
const typeNodes: ts.Node[] = []
|
|
25
|
+
|
|
26
|
+
if (!tree.length) {
|
|
27
|
+
return ''
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish)
|
|
31
|
+
const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable)
|
|
32
|
+
const isOptional = tree.some((item) => item.keyword === schemaKeywords.optional)
|
|
33
|
+
|
|
34
|
+
let type =
|
|
35
|
+
(tree
|
|
36
|
+
.map((schema, _index, siblings) =>
|
|
37
|
+
parse(
|
|
38
|
+
{ parent: undefined, current: schema, siblings },
|
|
39
|
+
{
|
|
40
|
+
name,
|
|
41
|
+
typeName: typedName,
|
|
42
|
+
description,
|
|
43
|
+
keysToOmit,
|
|
44
|
+
optionalType,
|
|
45
|
+
enumType,
|
|
46
|
+
mapper,
|
|
47
|
+
},
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
.filter(Boolean)
|
|
51
|
+
.at(0) as ts.TypeNode) || typeKeywordMapper.undefined()
|
|
52
|
+
|
|
53
|
+
if (isNullable) {
|
|
54
|
+
type = factory.createUnionDeclaration({
|
|
55
|
+
nodes: [type, factory.keywordTypeNodes.null],
|
|
56
|
+
}) as ts.TypeNode
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (isNullish && ['undefined', 'questionTokenAndUndefined'].includes(optionalType as string)) {
|
|
60
|
+
type = factory.createUnionDeclaration({
|
|
61
|
+
nodes: [type, factory.keywordTypeNodes.undefined],
|
|
62
|
+
}) as ts.TypeNode
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (isOptional && ['undefined', 'questionTokenAndUndefined'].includes(optionalType as string)) {
|
|
66
|
+
type = factory.createUnionDeclaration({
|
|
67
|
+
nodes: [type, factory.keywordTypeNodes.undefined],
|
|
68
|
+
}) as ts.TypeNode
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const node = factory.createTypeAliasDeclaration({
|
|
72
|
+
modifiers: [factory.modifiers.export],
|
|
73
|
+
name,
|
|
74
|
+
type: keysToOmit?.length
|
|
75
|
+
? factory.createOmitDeclaration({
|
|
76
|
+
keys: keysToOmit,
|
|
77
|
+
type,
|
|
78
|
+
nonNullable: true,
|
|
79
|
+
})
|
|
80
|
+
: type,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum)
|
|
84
|
+
|
|
85
|
+
const enums = [...new Set(enumSchemas)].map((enumSchema) => {
|
|
86
|
+
const name = enumType === 'asPascalConst' ? transformers.pascalCase(enumSchema.args.name) : transformers.camelCase(enumSchema.args.name)
|
|
87
|
+
const typeName = enumSchema.args.typeName
|
|
88
|
+
|
|
89
|
+
const [nameNode, typeNode] = factory.createEnumDeclaration({
|
|
90
|
+
name,
|
|
91
|
+
typeName,
|
|
92
|
+
enums: enumSchema.args.items
|
|
93
|
+
.map((item) => (item.value === undefined ? undefined : [transformers.trimQuotes(item.name?.toString()), item.value]))
|
|
94
|
+
.filter(Boolean) as unknown as [string, string][],
|
|
95
|
+
type: enumType,
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
nameNode,
|
|
100
|
+
typeNode,
|
|
101
|
+
name,
|
|
102
|
+
typeName,
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
typeNodes.push(
|
|
107
|
+
factory.appendJSDocToNode({
|
|
108
|
+
node,
|
|
109
|
+
comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),
|
|
110
|
+
}),
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<Fragment>
|
|
115
|
+
{enums.map(({ name, nameNode, typeName, typeNode }, index) => (
|
|
116
|
+
<Fragment key={[name, nameNode].join('-')}>
|
|
117
|
+
{nameNode && (
|
|
118
|
+
<File.Source name={name} isExportable isIndexable>
|
|
119
|
+
{print([nameNode])}
|
|
120
|
+
</File.Source>
|
|
121
|
+
)}
|
|
122
|
+
{
|
|
123
|
+
<File.Source
|
|
124
|
+
name={typeName}
|
|
125
|
+
isIndexable
|
|
126
|
+
isExportable={['enum', 'asConst', 'constEnum', 'literal', undefined].includes(enumType)}
|
|
127
|
+
isTypeOnly={['asConst', 'constEnum', 'literal', undefined].includes(enumType)}
|
|
128
|
+
>
|
|
129
|
+
{print([typeNode])}
|
|
130
|
+
</File.Source>
|
|
131
|
+
}
|
|
132
|
+
</Fragment>
|
|
133
|
+
))}
|
|
134
|
+
{enums.every((item) => item.typeName !== name) && (
|
|
135
|
+
<File.Source name={typedName} isTypeOnly isExportable isIndexable>
|
|
136
|
+
{print(typeNodes)}
|
|
137
|
+
</File.Source>
|
|
138
|
+
)}
|
|
139
|
+
</Fragment>
|
|
140
|
+
)
|
|
141
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @description Null response
|
|
4
|
+
*/
|
|
5
|
+
export type CreatePets201 = (error & {
|
|
6
|
+
/**
|
|
7
|
+
* @type object | undefined
|
|
8
|
+
*/
|
|
9
|
+
name?: errorCode;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @description unexpected error
|
|
14
|
+
*/
|
|
15
|
+
export type CreatePetsError = error;
|
|
16
|
+
|
|
17
|
+
export type CreatePetsMutationRequest = {
|
|
18
|
+
/**
|
|
19
|
+
* @type string
|
|
20
|
+
*/
|
|
21
|
+
name: string;
|
|
22
|
+
/**
|
|
23
|
+
* @type string
|
|
24
|
+
*/
|
|
25
|
+
tag: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type CreatePetsMutationResponse = createPets201;
|
|
29
|
+
|
|
30
|
+
export type createPetsMutation = {
|
|
31
|
+
Response: createPets201;
|
|
32
|
+
Request: createPetsMutationRequest;
|
|
33
|
+
Errors: any;
|
|
34
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @description Null response
|
|
4
|
+
*/
|
|
5
|
+
export type CreatePets201 = (error & {
|
|
6
|
+
/**
|
|
7
|
+
* @type object | undefined
|
|
8
|
+
*/
|
|
9
|
+
name?: errorCode;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @description unexpected error
|
|
14
|
+
*/
|
|
15
|
+
export type CreatePetsError = error;
|
|
16
|
+
|
|
17
|
+
export type CreatePetsMutationRequest = {
|
|
18
|
+
/**
|
|
19
|
+
* @type string
|
|
20
|
+
*/
|
|
21
|
+
name: string;
|
|
22
|
+
/**
|
|
23
|
+
* @type string
|
|
24
|
+
*/
|
|
25
|
+
tag: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type CreatePetsMutationResponse = createPets201;
|
|
29
|
+
|
|
30
|
+
export type createPetsMutation = {
|
|
31
|
+
Response: createPets201;
|
|
32
|
+
Request: createPetsMutationRequest;
|
|
33
|
+
Errors: any;
|
|
34
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const enumAllOfReasonEnum2 = {
|
|
2
|
+
"created_at": "created_at",
|
|
3
|
+
"description": "description"
|
|
4
|
+
} as const;
|
|
5
|
+
|
|
6
|
+
export type EnumAllOfReasonEnum2 = (typeof enumAllOfReasonEnum2)[keyof typeof enumAllOfReasonEnum2];
|
|
7
|
+
|
|
8
|
+
export type enumAllOf = {
|
|
9
|
+
reason?: EnumAllOfReasonEnum2;
|
|
10
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const enumArrayIdentifierEnum2 = {
|
|
2
|
+
"NW": "NW",
|
|
3
|
+
"NE": "NE",
|
|
4
|
+
"SW": "SW",
|
|
5
|
+
"SE": "SE"
|
|
6
|
+
} as const;
|
|
7
|
+
|
|
8
|
+
export type EnumArrayIdentifierEnum2 = (typeof enumArrayIdentifierEnum2)[keyof typeof enumArrayIdentifierEnum2];
|
|
9
|
+
|
|
10
|
+
export type enumArray = {
|
|
11
|
+
/**
|
|
12
|
+
* @type array | undefined
|
|
13
|
+
*/
|
|
14
|
+
identifier?: [
|
|
15
|
+
number,
|
|
16
|
+
string,
|
|
17
|
+
EnumArrayIdentifierEnum2
|
|
18
|
+
];
|
|
19
|
+
};
|