@kubb/plugin-ts 3.8.0 → 3.9.1
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-OJLHIBYC.js → chunk-45GERXQD.js} +47 -26
- package/dist/chunk-45GERXQD.js.map +1 -0
- package/dist/{chunk-YCJCRZF6.js → chunk-LEN5TPHR.js} +15 -13
- package/dist/chunk-LEN5TPHR.js.map +1 -0
- package/dist/{chunk-VBEBZKJX.cjs → chunk-LWIFDYGQ.cjs} +53 -32
- package/dist/chunk-LWIFDYGQ.cjs.map +1 -0
- package/dist/{chunk-OFELQKSZ.cjs → chunk-YOHDAJ4F.cjs} +15 -13
- package/dist/chunk-YOHDAJ4F.cjs.map +1 -0
- package/dist/components.cjs +3 -3
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.js +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.js +2 -2
- package/package.json +11 -11
- package/src/generators/__snapshots__/bodyUploadFileApiAssetsPost.ts +5 -0
- package/src/generators/__snapshots__/catTypeAsConst.ts +5 -0
- package/src/generators/__snapshots__/createPet.ts +5 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +5 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeVoid.ts +5 -0
- package/src/generators/__snapshots__/deletePet.ts +5 -0
- package/src/generators/__snapshots__/dogTypeAsConst.ts +5 -0
- package/src/generators/__snapshots__/enumAllOf.ts +5 -0
- package/src/generators/__snapshots__/enumArray.ts +5 -0
- package/src/generators/__snapshots__/enumArray20.ts +5 -0
- package/src/generators/__snapshots__/enumInObject.ts +5 -0
- package/src/generators/__snapshots__/enumItems.ts +5 -0
- package/src/generators/__snapshots__/enumNames.ts +5 -0
- package/src/generators/__snapshots__/enumNamesConst.ts +5 -0
- package/src/generators/__snapshots__/enumNamesLiteral.ts +5 -0
- package/src/generators/__snapshots__/enumNamesPascalConst.ts +5 -0
- package/src/generators/__snapshots__/enumNamesType.ts +5 -0
- package/src/generators/__snapshots__/enumNullableMember.ts +5 -0
- package/src/generators/__snapshots__/enumNullableType.ts +5 -0
- package/src/generators/__snapshots__/enumString.ts +5 -0
- package/src/generators/__snapshots__/enumVarNamesType.ts +5 -0
- package/src/generators/__snapshots__/fooBase.ts +5 -0
- package/src/generators/__snapshots__/fooNumber.ts +5 -0
- package/src/generators/__snapshots__/getPets.ts +5 -0
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +5 -0
- package/src/generators/__snapshots__/nullConstNull.ts +5 -0
- package/src/generators/__snapshots__/numberValueConst.ts +5 -0
- package/src/generators/__snapshots__/petMapper.ts +5 -0
- package/src/generators/__snapshots__/petQuestionToken.ts +5 -0
- package/src/generators/__snapshots__/petQuestionTokenAndUndefined.ts +5 -0
- package/src/generators/__snapshots__/petUndefined.ts +5 -0
- package/src/generators/__snapshots__/pets.ts +5 -0
- package/src/generators/__snapshots__/petsInterface.ts +5 -0
- package/src/generators/__snapshots__/petsStoreAdvancedDiscriminator.ts +5 -0
- package/src/generators/__snapshots__/petsStoreDiscriminator.ts +5 -0
- package/src/generators/__snapshots__/petsStoreRef.ts +5 -0
- package/src/generators/__snapshots__/plainDateDate.ts +5 -0
- package/src/generators/__snapshots__/plainDateString.ts +5 -0
- package/src/generators/__snapshots__/plainEmail.ts +5 -0
- package/src/generators/__snapshots__/plainFile.ts +5 -0
- package/src/generators/__snapshots__/plainTimeDate.ts +5 -0
- package/src/generators/__snapshots__/plainUuid.ts +5 -0
- package/src/generators/__snapshots__/readOnly.ts +5 -0
- package/src/generators/__snapshots__/showPetById.ts +5 -0
- package/src/generators/__snapshots__/stringValueConst.ts +5 -0
- package/src/generators/oasGenerator.tsx +7 -1
- package/src/generators/typeGenerator.tsx +9 -2
- package/src/parser.ts +12 -8
- package/dist/chunk-OFELQKSZ.cjs.map +0 -1
- package/dist/chunk-OJLHIBYC.js.map +0 -1
- package/dist/chunk-VBEBZKJX.cjs.map +0 -1
- package/dist/chunk-YCJCRZF6.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ts",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.1",
|
|
4
4
|
"description": "Generator plugin-ts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
],
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "
|
|
15
|
+
"url": "https://github.com/kubb-labs/kubb.git",
|
|
16
16
|
"directory": "packages/plugin-ts"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"author": "
|
|
19
|
+
"author": "stijnvanhulle",
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
@@ -58,20 +58,20 @@
|
|
|
58
58
|
"!/**/__tests__/**"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@kubb/core": "3.
|
|
62
|
-
"@kubb/fs": "3.
|
|
63
|
-
"@kubb/oas": "3.
|
|
64
|
-
"@kubb/parser-ts": "3.
|
|
65
|
-
"@kubb/plugin-oas": "3.
|
|
66
|
-
"@kubb/react": "3.
|
|
61
|
+
"@kubb/core": "3.9.1",
|
|
62
|
+
"@kubb/fs": "3.9.1",
|
|
63
|
+
"@kubb/oas": "3.9.1",
|
|
64
|
+
"@kubb/parser-ts": "3.9.1",
|
|
65
|
+
"@kubb/plugin-oas": "3.9.1",
|
|
66
|
+
"@kubb/react": "3.9.1"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@types/react": "^18.3.20",
|
|
70
70
|
"react": "^18.3.1",
|
|
71
71
|
"tsup": "^8.4.0",
|
|
72
72
|
"typescript": "^5.8.3",
|
|
73
|
-
"@kubb/config-ts": "3.
|
|
74
|
-
"@kubb/config-tsup": "3.
|
|
73
|
+
"@kubb/config-ts": "3.9.1",
|
|
74
|
+
"@kubb/config-tsup": "3.9.1"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@kubb/react": "^3.0.0"
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by Kubb (https://kubb.dev/).
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* @description The value of this keyword MAY be null.\nUse of this keyword is functionally equivalent to an \"enum\" (Section 6.1.2) with a single value.\nAn instance validates successfully against this keyword if its value is equal to the value of the keyword.\n
|
|
3
8
|
*/
|
|
@@ -20,7 +20,13 @@ export const oasGenerator = createReactGenerator<PluginTs>({
|
|
|
20
20
|
const file = pluginManager.getFile({ name: 'oas', extname: '.ts', pluginKey })
|
|
21
21
|
|
|
22
22
|
return (
|
|
23
|
-
<File
|
|
23
|
+
<File
|
|
24
|
+
baseName={file.baseName}
|
|
25
|
+
path={file.path}
|
|
26
|
+
meta={file.meta}
|
|
27
|
+
banner={getBanner({ oas, output, config: pluginManager.config })}
|
|
28
|
+
footer={getFooter({ oas, output })}
|
|
29
|
+
>
|
|
24
30
|
<File.Import name={['Infer']} path="@kubb/oas" isTypeOnly />
|
|
25
31
|
|
|
26
32
|
<OasType name={'oas'} typeName={'Oas'} api={oas.api} />
|
|
@@ -163,7 +163,7 @@ export const typeGenerator = createReactGenerator<PluginTs>({
|
|
|
163
163
|
baseName={file.baseName}
|
|
164
164
|
path={file.path}
|
|
165
165
|
meta={file.meta}
|
|
166
|
-
banner={getBanner({ oas, output: plugin.options.output })}
|
|
166
|
+
banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}
|
|
167
167
|
footer={getFooter({ oas, output: plugin.options.output })}
|
|
168
168
|
>
|
|
169
169
|
{operationSchemas.map(mapOperationSchema)}
|
|
@@ -181,6 +181,7 @@ export const typeGenerator = createReactGenerator<PluginTs>({
|
|
|
181
181
|
plugin: {
|
|
182
182
|
options: { output },
|
|
183
183
|
},
|
|
184
|
+
pluginManager,
|
|
184
185
|
} = useApp<PluginTs>()
|
|
185
186
|
const oas = useOas()
|
|
186
187
|
|
|
@@ -198,7 +199,13 @@ export const typeGenerator = createReactGenerator<PluginTs>({
|
|
|
198
199
|
}
|
|
199
200
|
|
|
200
201
|
return (
|
|
201
|
-
<File
|
|
202
|
+
<File
|
|
203
|
+
baseName={type.file.baseName}
|
|
204
|
+
path={type.file.path}
|
|
205
|
+
meta={type.file.meta}
|
|
206
|
+
banner={getBanner({ oas, output, config: pluginManager.config })}
|
|
207
|
+
footer={getFooter({ oas, output })}
|
|
208
|
+
>
|
|
202
209
|
{mode === 'split' && imports.map((imp, index) => <File.Import key={index} root={type.file.path} path={imp.path} name={imp.name} isTypeOnly />)}
|
|
203
210
|
<Type
|
|
204
211
|
name={type.name}
|
package/src/parser.ts
CHANGED
|
@@ -81,7 +81,6 @@ export const typeKeywordMapper = {
|
|
|
81
81
|
type === 'string' ? factory.keywordTypeNodes.string : factory.createTypeReferenceNode(factory.createIdentifier('Date')),
|
|
82
82
|
uuid: () => factory.keywordTypeNodes.string,
|
|
83
83
|
url: () => factory.keywordTypeNodes.string,
|
|
84
|
-
strict: undefined,
|
|
85
84
|
default: undefined,
|
|
86
85
|
and: (nodes?: ts.TypeNode[]) => {
|
|
87
86
|
if (!nodes) {
|
|
@@ -118,6 +117,7 @@ export const typeKeywordMapper = {
|
|
|
118
117
|
schema: undefined,
|
|
119
118
|
catchall: undefined,
|
|
120
119
|
name: undefined,
|
|
120
|
+
interface: undefined,
|
|
121
121
|
} satisfies SchemaMapper<ts.Node | null | undefined>
|
|
122
122
|
|
|
123
123
|
type ParserOptions = {
|
|
@@ -138,7 +138,7 @@ type ParserOptions = {
|
|
|
138
138
|
mapper?: Record<string, ts.PropertySignature>
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
export function parse({ current, siblings }: SchemaTree, options: ParserOptions): ts.Node | null | undefined {
|
|
141
|
+
export function parse({ current, siblings, name }: SchemaTree, options: ParserOptions): ts.Node | null | undefined {
|
|
142
142
|
const value = typeKeywordMapper[current.keyword as keyof typeof typeKeywordMapper]
|
|
143
143
|
|
|
144
144
|
if (!value) {
|
|
@@ -147,17 +147,19 @@ export function parse({ current, siblings }: SchemaTree, options: ParserOptions)
|
|
|
147
147
|
|
|
148
148
|
if (isKeyword(current, schemaKeywords.union)) {
|
|
149
149
|
return typeKeywordMapper.union(
|
|
150
|
-
current.args.map((schema) => parse({ parent: current, current: schema, siblings }, options)).filter(Boolean) as ts.TypeNode[],
|
|
150
|
+
current.args.map((schema) => parse({ parent: current, name: name, current: schema, siblings }, options)).filter(Boolean) as ts.TypeNode[],
|
|
151
151
|
)
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
if (isKeyword(current, schemaKeywords.and)) {
|
|
155
|
-
return typeKeywordMapper.and(
|
|
155
|
+
return typeKeywordMapper.and(
|
|
156
|
+
current.args.map((schema) => parse({ parent: current, name: name, current: schema, siblings }, options)).filter(Boolean) as ts.TypeNode[],
|
|
157
|
+
)
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
if (isKeyword(current, schemaKeywords.array)) {
|
|
159
161
|
return typeKeywordMapper.array(
|
|
160
|
-
current.args.items.map((schema) => parse({ parent: current, current: schema, siblings }, options)).filter(Boolean) as ts.TypeNode[],
|
|
162
|
+
current.args.items.map((schema) => parse({ parent: current, name: name, current: schema, siblings }, options)).filter(Boolean) as ts.TypeNode[],
|
|
161
163
|
)
|
|
162
164
|
}
|
|
163
165
|
|
|
@@ -175,7 +177,7 @@ export function parse({ current, siblings }: SchemaTree, options: ParserOptions)
|
|
|
175
177
|
|
|
176
178
|
if (isKeyword(current, schemaKeywords.tuple)) {
|
|
177
179
|
return typeKeywordMapper.tuple(
|
|
178
|
-
current.args.items.map((schema) => parse({ parent: current, current: schema, siblings }, options)).filter(Boolean) as ts.TypeNode[],
|
|
180
|
+
current.args.items.map((schema) => parse({ parent: current, name: name, current: schema, siblings }, options)).filter(Boolean) as ts.TypeNode[],
|
|
179
181
|
)
|
|
180
182
|
}
|
|
181
183
|
|
|
@@ -211,7 +213,9 @@ export function parse({ current, siblings }: SchemaTree, options: ParserOptions)
|
|
|
211
213
|
const maxSchema = schemas.find((schema) => schema.keyword === schemaKeywords.max) as SchemaKeywordMapper['max'] | undefined
|
|
212
214
|
const matchesSchema = schemas.find((schema) => schema.keyword === schemaKeywords.matches) as SchemaKeywordMapper['matches'] | undefined
|
|
213
215
|
|
|
214
|
-
let type = schemas
|
|
216
|
+
let type = schemas
|
|
217
|
+
.map((schema) => parse({ parent: current, name: name, current: schema, siblings: schemas }, options))
|
|
218
|
+
.filter(Boolean)[0] as ts.TypeNode
|
|
215
219
|
|
|
216
220
|
if (isNullable) {
|
|
217
221
|
type = factory.createUnionDeclaration({
|
|
@@ -258,7 +262,7 @@ export function parse({ current, siblings }: SchemaTree, options: ParserOptions)
|
|
|
258
262
|
const additionalProperties = current.args?.additionalProperties?.length
|
|
259
263
|
? factory.createIndexSignature(
|
|
260
264
|
current.args.additionalProperties
|
|
261
|
-
.map((schema) => parse({ parent: current, current: schema, siblings }, options))
|
|
265
|
+
.map((schema) => parse({ parent: current, name: name, current: schema, siblings }, options))
|
|
262
266
|
.filter(Boolean)
|
|
263
267
|
.at(0) as ts.TypeNode,
|
|
264
268
|
)
|