@kubb/plugin-ts 3.0.0-alpha.6 → 3.0.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-3TP3WKCF.js → chunk-DH5UFT3R.js} +24 -14
- package/dist/{chunk-3TP3WKCF.js.map → chunk-DH5UFT3R.js.map} +1 -1
- package/dist/{chunk-QBRUTU67.cjs → chunk-NNQVIJV5.cjs} +38 -28
- package/dist/chunk-NNQVIJV5.cjs.map +1 -0
- package/dist/{chunk-YUTLPFP7.cjs → chunk-SEH6NUCX.cjs} +3 -3
- package/dist/{chunk-YUTLPFP7.cjs.map → chunk-SEH6NUCX.cjs.map} +1 -1
- package/dist/{chunk-3LGDZFZS.js → chunk-TTGZBH7H.js} +3 -3
- package/dist/{chunk-3LGDZFZS.js.map → chunk-TTGZBH7H.js.map} +1 -1
- package/dist/components.cjs +4 -4
- package/dist/components.js +2 -2
- package/dist/index.cjs +3 -3
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -2
- package/dist/oas.cjs +2 -2
- package/dist/oas.js +1 -1
- package/package.json +11 -11
- package/src/components/OasType.tsx +1 -1
- package/src/components/OperationSchema.tsx +5 -3
- package/src/components/Schema.tsx +12 -13
- package/src/components/__snapshots__/Schema/pets.ts +6 -6
- package/src/components/__snapshots__/Schema/showPetById.ts +6 -6
- package/src/parser/index.ts +1 -0
- package/src/plugin.ts +10 -4
- package/src/types.ts +2 -1
- package/dist/chunk-QBRUTU67.cjs.map +0 -1
package/dist/components.cjs
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkNNQVIJV5cjs = require('./chunk-NNQVIJV5.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkSEH6NUCXcjs = require('./chunk-SEH6NUCX.cjs');
|
|
9
9
|
|
|
10
10
|
// src/components/index.ts
|
|
11
|
-
|
|
11
|
+
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
exports.OasType =
|
|
16
|
+
exports.OasType = _chunkNNQVIJV5cjs.OasType; exports.OperationSchema = _chunkNNQVIJV5cjs.OperationSchema; exports.Schema = _chunkNNQVIJV5cjs.Schema;
|
|
17
17
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.js
CHANGED
|
@@ -2,10 +2,10 @@ import {
|
|
|
2
2
|
OasType,
|
|
3
3
|
OperationSchema,
|
|
4
4
|
Schema
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-DH5UFT3R.js";
|
|
6
6
|
import {
|
|
7
7
|
init_esm_shims
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-TTGZBH7H.js";
|
|
9
9
|
|
|
10
10
|
// src/components/index.ts
|
|
11
11
|
init_esm_shims();
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
require('./chunk-
|
|
4
|
+
var _chunkNNQVIJV5cjs = require('./chunk-NNQVIJV5.cjs');
|
|
5
|
+
require('./chunk-SEH6NUCX.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports.pluginTs =
|
|
9
|
+
exports.pluginTs = _chunkNNQVIJV5cjs.pluginTs; exports.pluginTsName = _chunkNNQVIJV5cjs.pluginTsName;
|
|
10
10
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
2
|
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
3
3
|
import * as KubbFile from '@kubb/fs/types';
|
|
4
|
-
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
5
4
|
import { ts } from '@kubb/parser-ts';
|
|
5
|
+
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
6
6
|
|
|
7
7
|
type Options = {
|
|
8
8
|
output?: {
|
|
@@ -58,6 +58,7 @@ type Options = {
|
|
|
58
58
|
/**
|
|
59
59
|
* Choose to use `enum` or `as const` for enums
|
|
60
60
|
* @default 'asConst'
|
|
61
|
+
* asPascalConst is deprecated
|
|
61
62
|
*/
|
|
62
63
|
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
63
64
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _kubb_core from '@kubb/core';
|
|
2
2
|
import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
|
|
3
3
|
import * as KubbFile from '@kubb/fs/types';
|
|
4
|
-
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
5
4
|
import { ts } from '@kubb/parser-ts';
|
|
5
|
+
import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
|
|
6
6
|
|
|
7
7
|
type Options = {
|
|
8
8
|
output?: {
|
|
@@ -58,6 +58,7 @@ type Options = {
|
|
|
58
58
|
/**
|
|
59
59
|
* Choose to use `enum` or `as const` for enums
|
|
60
60
|
* @default 'asConst'
|
|
61
|
+
* asPascalConst is deprecated
|
|
61
62
|
*/
|
|
62
63
|
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal';
|
|
63
64
|
/**
|
package/dist/index.js
CHANGED
package/dist/oas.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkSEH6NUCXcjs = require('./chunk-SEH6NUCX.cjs');
|
|
4
4
|
|
|
5
5
|
// src/oas/index.ts
|
|
6
|
-
|
|
6
|
+
_chunkSEH6NUCXcjs.init_cjs_shims.call(void 0, );
|
|
7
7
|
//# sourceMappingURL=oas.cjs.map
|
package/dist/oas.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ts",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.7",
|
|
4
4
|
"description": "Generator plugin-ts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"!/**/__tests__/**"
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@kubb/core": "3.0.0-alpha.
|
|
54
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
55
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
56
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
57
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
58
|
-
"@kubb/react": "3.0.0-alpha.
|
|
53
|
+
"@kubb/core": "3.0.0-alpha.7",
|
|
54
|
+
"@kubb/fs": "3.0.0-alpha.7",
|
|
55
|
+
"@kubb/oas": "3.0.0-alpha.7",
|
|
56
|
+
"@kubb/parser-ts": "3.0.0-alpha.7",
|
|
57
|
+
"@kubb/plugin-oas": "3.0.0-alpha.7",
|
|
58
|
+
"@kubb/react": "3.0.0-alpha.7"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/react": "^18.3.4",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"react": "^18.3.1",
|
|
64
64
|
"tsup": "^8.2.4",
|
|
65
65
|
"typescript": "^5.5.4",
|
|
66
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
67
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
68
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
66
|
+
"@kubb/config-biome": "3.0.0-alpha.7",
|
|
67
|
+
"@kubb/config-ts": "3.0.0-alpha.7",
|
|
68
|
+
"@kubb/config-tsup": "3.0.0-alpha.7"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@kubb/react": "3.0.0-alpha.
|
|
71
|
+
"@kubb/react": "3.0.0-alpha.7"
|
|
72
72
|
},
|
|
73
73
|
"engines": {
|
|
74
74
|
"node": ">=20"
|
|
@@ -85,7 +85,7 @@ function printCombinedSchema({
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
const namespaceNode = factory.createTypeAliasDeclaration({
|
|
88
|
-
name
|
|
88
|
+
name,
|
|
89
89
|
type: factory.createTypeLiteralNode(
|
|
90
90
|
Object.keys(properties)
|
|
91
91
|
.map((key) => {
|
|
@@ -147,12 +147,14 @@ OperationSchema.File = function ({}: FileProps): ReactNode {
|
|
|
147
147
|
)
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
const combinedSchemaName = operation.method === 'get' ? `${factoryName}Query` : `${factoryName}Mutation`
|
|
151
|
+
|
|
150
152
|
return (
|
|
151
153
|
<File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
152
154
|
{items.map(mapItem)}
|
|
153
155
|
|
|
154
|
-
<File.Source name={
|
|
155
|
-
{printCombinedSchema({ name:
|
|
156
|
+
<File.Source name={combinedSchemaName} isExportable isTypeOnly>
|
|
157
|
+
{printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager })}
|
|
156
158
|
</File.Source>
|
|
157
159
|
</File>
|
|
158
160
|
)
|
|
@@ -26,6 +26,10 @@ export function Schema(props: Props): ReactNode {
|
|
|
26
26
|
},
|
|
27
27
|
} = useApp<PluginTs>()
|
|
28
28
|
|
|
29
|
+
if (enumType === 'asPascalConst') {
|
|
30
|
+
pluginManager.logger.emit('warning', `enumType '${enumType}' is deprecated`)
|
|
31
|
+
}
|
|
32
|
+
|
|
29
33
|
// all checks are also inside this.schema(React)
|
|
30
34
|
const resolvedName = pluginManager.resolveName({
|
|
31
35
|
name,
|
|
@@ -98,7 +102,7 @@ export function Schema(props: Props): ReactNode {
|
|
|
98
102
|
const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum)
|
|
99
103
|
|
|
100
104
|
const enums = enumSchemas.map((enumSchema) => {
|
|
101
|
-
const name = transformers.camelCase(enumSchema.args.name)
|
|
105
|
+
const name = enumType === 'asPascalConst' ? transformers.pascalCase(enumSchema.args.name) : transformers.camelCase(enumSchema.args.name)
|
|
102
106
|
const typeName = enumSchema.args.typeName
|
|
103
107
|
|
|
104
108
|
const [nameNode, typeNode] = factory.createEnumDeclaration({
|
|
@@ -125,25 +129,20 @@ export function Schema(props: Props): ReactNode {
|
|
|
125
129
|
}),
|
|
126
130
|
)
|
|
127
131
|
|
|
128
|
-
// const filterdNodes = typeNodes.filter(
|
|
129
|
-
// (node: ts.Node) =>
|
|
130
|
-
// !enumNodes.some(
|
|
131
|
-
// (extraNode: ts.Node) => (extraNode as ts.TypeAliasDeclaration)?.name?.escapedText === (node as ts.TypeAliasDeclaration)?.name?.escapedText,
|
|
132
|
-
// ),
|
|
133
|
-
// )
|
|
134
|
-
|
|
135
132
|
return (
|
|
136
133
|
<Fragment>
|
|
137
134
|
{enums.map(({ name, nameNode, typeName, typeNode }, index) => (
|
|
138
|
-
<Fragment key={
|
|
135
|
+
<Fragment key={[name, nameNode].join('-')}>
|
|
139
136
|
{nameNode && (
|
|
140
137
|
<File.Source name={name} isExportable>
|
|
141
138
|
{print(nameNode)}
|
|
142
139
|
</File.Source>
|
|
143
140
|
)}
|
|
144
|
-
|
|
145
|
-
{
|
|
146
|
-
|
|
141
|
+
{
|
|
142
|
+
<File.Source name={typeName} isExportable={['enum', 'asConst', 'constEnum', 'literal', undefined].includes(enumType)} isTypeOnly>
|
|
143
|
+
{print(typeNode)}
|
|
144
|
+
</File.Source>
|
|
145
|
+
}
|
|
147
146
|
</Fragment>
|
|
148
147
|
))}
|
|
149
148
|
{enums.every((item) => item.typeName !== resolvedName) && (
|
|
@@ -162,7 +161,7 @@ Schema.File = function ({}: FileProps): ReactNode {
|
|
|
162
161
|
const { schema } = useSchema()
|
|
163
162
|
|
|
164
163
|
return (
|
|
165
|
-
<Oas.Schema.File output={pluginManager.config.output.path}>
|
|
164
|
+
<Oas.Schema.File isTypeOnly output={pluginManager.config.output.path}>
|
|
166
165
|
<Schema description={schema?.description} />
|
|
167
166
|
</Oas.Schema.File>
|
|
168
167
|
)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @description Null response
|
|
3
3
|
*/
|
|
4
|
-
export type
|
|
4
|
+
export type createPets201 = any;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @description unexpected error
|
|
8
8
|
*/
|
|
9
|
-
export type
|
|
9
|
+
export type createPetsError = error;
|
|
10
10
|
|
|
11
|
-
export type
|
|
11
|
+
export type createPetsMutationRequest = {
|
|
12
12
|
/**
|
|
13
13
|
* @type string
|
|
14
14
|
*/
|
|
@@ -19,9 +19,9 @@ export type CreatePetsMutationRequest = {
|
|
|
19
19
|
tag: string;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
export type
|
|
22
|
+
export type createPetsMutationResponse = any;
|
|
23
23
|
|
|
24
24
|
export type CreatePetsMutation = {
|
|
25
|
-
Response:
|
|
26
|
-
Request:
|
|
25
|
+
Response: createPetsMutationResponse;
|
|
26
|
+
Request: createPetsMutationRequest;
|
|
27
27
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type showPetByIdPathParams = {
|
|
2
2
|
/**
|
|
3
3
|
* @description The id of the pet to retrieve
|
|
4
4
|
* @type string
|
|
@@ -14,19 +14,19 @@ export type ShowPetByIdPathParams = {
|
|
|
14
14
|
/**
|
|
15
15
|
* @description Expected response to a valid request
|
|
16
16
|
*/
|
|
17
|
-
export type
|
|
17
|
+
export type showPetById200 = pet;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* @description unexpected error
|
|
21
21
|
*/
|
|
22
|
-
export type
|
|
22
|
+
export type showPetByIdError = error;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @description Expected response to a valid request
|
|
26
26
|
*/
|
|
27
|
-
export type
|
|
27
|
+
export type showPetByIdQueryResponse = pet;
|
|
28
28
|
|
|
29
29
|
export type ShowPetByIdQuery = {
|
|
30
|
-
Response:
|
|
31
|
-
PathParams:
|
|
30
|
+
Response: showPetByIdQueryResponse;
|
|
31
|
+
PathParams: showPetByIdPathParams;
|
|
32
32
|
};
|
package/src/parser/index.ts
CHANGED
|
@@ -120,6 +120,7 @@ type ParserOptions = {
|
|
|
120
120
|
optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'
|
|
121
121
|
/**
|
|
122
122
|
* @default `'asConst'`
|
|
123
|
+
* asPascalConst is deprecated
|
|
123
124
|
*/
|
|
124
125
|
enumType: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'
|
|
125
126
|
keysToOmit?: string[]
|
package/src/plugin.ts
CHANGED
|
@@ -34,6 +34,10 @@ export const pluginTs = createPlugin<PluginTs>((options) => {
|
|
|
34
34
|
|
|
35
35
|
return {
|
|
36
36
|
name: pluginTsName,
|
|
37
|
+
output: {
|
|
38
|
+
exportType: 'barrelNamed',
|
|
39
|
+
...output,
|
|
40
|
+
},
|
|
37
41
|
options: {
|
|
38
42
|
extName: output.extName,
|
|
39
43
|
transformers,
|
|
@@ -113,16 +117,18 @@ export const pluginTs = createPlugin<PluginTs>((options) => {
|
|
|
113
117
|
const operationFiles = await operationGenerator.build()
|
|
114
118
|
await this.addFile(...operationFiles)
|
|
115
119
|
|
|
116
|
-
if (this.config.output.
|
|
117
|
-
const
|
|
120
|
+
if (this.config.output.exportType) {
|
|
121
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
118
122
|
root,
|
|
119
123
|
output,
|
|
120
124
|
files: this.fileManager.files,
|
|
121
|
-
|
|
125
|
+
meta: {
|
|
126
|
+
pluginKey: this.plugin.key,
|
|
127
|
+
},
|
|
122
128
|
logger: this.logger,
|
|
123
129
|
})
|
|
124
130
|
|
|
125
|
-
await this.addFile(...
|
|
131
|
+
await this.addFile(...barrelFiles)
|
|
126
132
|
}
|
|
127
133
|
},
|
|
128
134
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
2
|
import type * as KubbFile from '@kubb/fs/types'
|
|
3
|
-
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
4
3
|
import type { ts } from '@kubb/parser-ts'
|
|
4
|
+
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
5
5
|
|
|
6
6
|
export type Options = {
|
|
7
7
|
output?: {
|
|
@@ -57,6 +57,7 @@ export type Options = {
|
|
|
57
57
|
/**
|
|
58
58
|
* Choose to use `enum` or `as const` for enums
|
|
59
59
|
* @default 'asConst'
|
|
60
|
+
* asPascalConst is deprecated
|
|
60
61
|
*/
|
|
61
62
|
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal'
|
|
62
63
|
/**
|