@kubb/plugin-ts 3.3.3 → 3.3.4
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-CM3JWDSC.cjs → chunk-JZIXHFCA.cjs} +13 -11
- package/dist/chunk-JZIXHFCA.cjs.map +1 -0
- package/dist/{chunk-XQHAKH5D.js → chunk-TFCUDXXU.js} +5 -3
- package/dist/chunk-TFCUDXXU.js.map +1 -0
- package/dist/{chunk-7TGSNOHU.js → chunk-U7IYQJBH.js} +22 -8
- package/dist/chunk-U7IYQJBH.js.map +1 -0
- package/dist/{chunk-CCC3JJQ5.cjs → chunk-YKKU2PFK.cjs} +22 -8
- package/dist/chunk-YKKU2PFK.cjs.map +1 -0
- package/dist/components.cjs +3 -3
- package/dist/components.d.cts +3 -2
- package/dist/components.d.ts +3 -2
- 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 +10 -10
- package/src/components/Type.tsx +16 -6
- package/src/generators/typeGenerator.tsx +2 -0
- package/src/parser.ts +6 -0
- package/dist/chunk-7TGSNOHU.js.map +0 -1
- package/dist/chunk-CCC3JJQ5.cjs.map +0 -1
- package/dist/chunk-CM3JWDSC.cjs.map +0 -1
- package/dist/chunk-XQHAKH5D.js.map +0 -1
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ts",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.4",
|
|
4
4
|
"description": "Generator plugin-ts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -58,20 +58,20 @@
|
|
|
58
58
|
"!/**/__tests__/**"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@kubb/core": "3.3.
|
|
62
|
-
"@kubb/fs": "3.3.
|
|
63
|
-
"@kubb/oas": "3.3.
|
|
64
|
-
"@kubb/parser-ts": "3.3.
|
|
65
|
-
"@kubb/plugin-oas": "3.3.
|
|
66
|
-
"@kubb/react": "3.3.
|
|
61
|
+
"@kubb/core": "3.3.4",
|
|
62
|
+
"@kubb/fs": "3.3.4",
|
|
63
|
+
"@kubb/oas": "3.3.4",
|
|
64
|
+
"@kubb/parser-ts": "3.3.4",
|
|
65
|
+
"@kubb/plugin-oas": "3.3.4",
|
|
66
|
+
"@kubb/react": "3.3.4"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@types/react": "^18.3.
|
|
69
|
+
"@types/react": "^18.3.17",
|
|
70
70
|
"react": "^18.3.1",
|
|
71
71
|
"tsup": "^8.3.5",
|
|
72
72
|
"typescript": "^5.7.2",
|
|
73
|
-
"@kubb/config-ts": "3.3.
|
|
74
|
-
"@kubb/config-tsup": "3.3.
|
|
73
|
+
"@kubb/config-ts": "3.3.4",
|
|
74
|
+
"@kubb/config-tsup": "3.3.4"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@kubb/react": "^3.0.0"
|
package/src/components/Type.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { File } from '@kubb/react'
|
|
2
2
|
|
|
3
3
|
import transformers from '@kubb/core/transformers'
|
|
4
|
+
import type { SchemaObject } from '@kubb/oas'
|
|
4
5
|
import { print } from '@kubb/parser-ts'
|
|
5
6
|
import * as factory from '@kubb/parser-ts/factory'
|
|
6
7
|
import { createTypeDeclaration } from '@kubb/parser-ts/factory'
|
|
@@ -13,6 +14,7 @@ import type { PluginTs } from '../types.ts'
|
|
|
13
14
|
type Props = {
|
|
14
15
|
name: string
|
|
15
16
|
typedName: string
|
|
17
|
+
schema: SchemaObject
|
|
16
18
|
tree: Array<Schema>
|
|
17
19
|
optionalType: PluginTs['resolvedOptions']['optionalType']
|
|
18
20
|
enumType: PluginTs['resolvedOptions']['enumType']
|
|
@@ -22,20 +24,20 @@ type Props = {
|
|
|
22
24
|
keysToOmit?: string[]
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
export function Type({ name, typedName, tree, keysToOmit, optionalType, syntaxType, enumType, mapper, description }: Props): ReactNode {
|
|
27
|
+
export function Type({ name, typedName, tree, keysToOmit, schema, optionalType, syntaxType, enumType, mapper, description }: Props): ReactNode {
|
|
26
28
|
const typeNodes: ts.Node[] = []
|
|
27
29
|
|
|
28
30
|
if (!tree.length) {
|
|
29
31
|
return ''
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
const
|
|
34
|
+
const schemaFromTree = tree.find((item) => item.keyword === schemaKeywords.schema)
|
|
33
35
|
|
|
34
36
|
let type =
|
|
35
37
|
(tree
|
|
36
|
-
.map((
|
|
38
|
+
.map((current, _index, siblings) =>
|
|
37
39
|
parse(
|
|
38
|
-
{ parent: undefined, current
|
|
40
|
+
{ parent: undefined, current, siblings },
|
|
39
41
|
{
|
|
40
42
|
name,
|
|
41
43
|
typedName,
|
|
@@ -51,7 +53,7 @@ export function Type({ name, typedName, tree, keysToOmit, optionalType, syntaxTy
|
|
|
51
53
|
.filter(Boolean)
|
|
52
54
|
.at(0) as ts.TypeNode) || typeKeywordMapper.undefined()
|
|
53
55
|
|
|
54
|
-
if (
|
|
56
|
+
if (schemaFromTree && isKeyword(schemaFromTree, schemaKeywords.schema) && schemaFromTree.args.type !== 'object') {
|
|
55
57
|
const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish)
|
|
56
58
|
const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable)
|
|
57
59
|
const isOptional = tree.some((item) => item.keyword === schemaKeywords.optional)
|
|
@@ -89,7 +91,15 @@ export function Type({ name, typedName, tree, keysToOmit, optionalType, syntaxTy
|
|
|
89
91
|
})
|
|
90
92
|
: type,
|
|
91
93
|
syntax: useTypeGeneration ? 'type' : 'interface',
|
|
92
|
-
|
|
94
|
+
comments: [
|
|
95
|
+
description ? `@description ${transformers.jsStringEscape(description)}` : undefined,
|
|
96
|
+
schema.deprecated ? '@deprecated' : undefined,
|
|
97
|
+
schema.minLength ? `@minLength ${schema.minLength}` : undefined,
|
|
98
|
+
schema.maxLength ? `@maxLength ${schema.maxLength}` : undefined,
|
|
99
|
+
schema.pattern ? `@pattern ${schema.pattern}` : undefined,
|
|
100
|
+
schema.default ? `@default ${schema.default}` : undefined,
|
|
101
|
+
schema.example ? `@example ${schema.example}` : undefined,
|
|
102
|
+
],
|
|
93
103
|
}),
|
|
94
104
|
)
|
|
95
105
|
|
|
@@ -146,6 +146,7 @@ export const typeGenerator = createReactGenerator<PluginTs>({
|
|
|
146
146
|
typedName={type.typedName}
|
|
147
147
|
description={description}
|
|
148
148
|
tree={tree}
|
|
149
|
+
schema={schema}
|
|
149
150
|
mapper={mapper}
|
|
150
151
|
enumType={enumType}
|
|
151
152
|
optionalType={optionalType}
|
|
@@ -196,6 +197,7 @@ export const typeGenerator = createReactGenerator<PluginTs>({
|
|
|
196
197
|
typedName={type.typedName}
|
|
197
198
|
description={schema.value.description}
|
|
198
199
|
tree={schema.tree}
|
|
200
|
+
schema={schema.value}
|
|
199
201
|
mapper={mapper}
|
|
200
202
|
enumType={enumType}
|
|
201
203
|
optionalType={optionalType}
|
package/src/parser.ts
CHANGED
|
@@ -206,6 +206,9 @@ export function parse({ parent, current, siblings }: SchemaTree, options: Parser
|
|
|
206
206
|
const defaultSchema = schemas.find((schema) => schema.keyword === schemaKeywords.default) as SchemaKeywordMapper['default'] | undefined
|
|
207
207
|
const exampleSchema = schemas.find((schema) => schema.keyword === schemaKeywords.example) as SchemaKeywordMapper['example'] | undefined
|
|
208
208
|
const schemaSchema = schemas.find((schema) => schema.keyword === schemaKeywords.schema) as SchemaKeywordMapper['schema'] | undefined
|
|
209
|
+
const minSchema = schemas.find((schema) => schema.keyword === schemaKeywords.min) as SchemaKeywordMapper['min'] | undefined
|
|
210
|
+
const maxSchema = schemas.find((schema) => schema.keyword === schemaKeywords.max) as SchemaKeywordMapper['max'] | undefined
|
|
211
|
+
const matchesSchema = schemas.find((schema) => schema.keyword === schemaKeywords.matches) as SchemaKeywordMapper['matches'] | undefined
|
|
209
212
|
|
|
210
213
|
let type = schemas.map((schema) => parse({ parent: current, current: schema, siblings }, options)).filter(Boolean)[0] as ts.TypeNode
|
|
211
214
|
|
|
@@ -239,6 +242,9 @@ export function parse({ parent, current, siblings }: SchemaTree, options: Parser
|
|
|
239
242
|
comments: [
|
|
240
243
|
describeSchema ? `@description ${transformers.jsStringEscape(describeSchema.args)}` : undefined,
|
|
241
244
|
deprecatedSchema ? '@deprecated' : undefined,
|
|
245
|
+
minSchema ? `@minLength ${minSchema.args}` : undefined,
|
|
246
|
+
maxSchema ? `@maxLength ${maxSchema.args}` : undefined,
|
|
247
|
+
matchesSchema ? `@pattern ${matchesSchema.args}` : undefined,
|
|
242
248
|
defaultSchema ? `@default ${defaultSchema.args}` : undefined,
|
|
243
249
|
exampleSchema ? `@example ${exampleSchema.args}` : undefined,
|
|
244
250
|
schemaSchema?.args?.type || schemaSchema?.args?.format
|