@kubb/plugin-ts 3.3.3 → 3.3.5

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { pluginTs, pluginTsName } from './chunk-XQHAKH5D.js';
2
- import './chunk-7TGSNOHU.js';
1
+ export { pluginTs, pluginTsName } from './chunk-AYNI7BPH.js';
2
+ import './chunk-EAOG7QZN.js';
3
3
  //# sourceMappingURL=index.js.map
4
4
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-ts",
3
- "version": "3.3.3",
3
+ "version": "3.3.5",
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.3",
62
- "@kubb/fs": "3.3.3",
63
- "@kubb/oas": "3.3.3",
64
- "@kubb/parser-ts": "3.3.3",
65
- "@kubb/plugin-oas": "3.3.3",
66
- "@kubb/react": "3.3.3"
61
+ "@kubb/core": "3.3.5",
62
+ "@kubb/fs": "3.3.5",
63
+ "@kubb/oas": "3.3.5",
64
+ "@kubb/parser-ts": "3.3.5",
65
+ "@kubb/plugin-oas": "3.3.5",
66
+ "@kubb/react": "3.3.5"
67
67
  },
68
68
  "devDependencies": {
69
- "@types/react": "^18.3.16",
69
+ "@types/react": "^18.3.18",
70
70
  "react": "^18.3.1",
71
71
  "tsup": "^8.3.5",
72
72
  "typescript": "^5.7.2",
73
- "@kubb/config-ts": "3.3.3",
74
- "@kubb/config-tsup": "3.3.3"
73
+ "@kubb/config-ts": "3.3.5",
74
+ "@kubb/config-tsup": "3.3.5"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@kubb/react": "^3.0.0"
@@ -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 schema = tree.find((item) => item.keyword === schemaKeywords.schema)
34
+ const schemaFromTree = tree.find((item) => item.keyword === schemaKeywords.schema)
33
35
 
34
36
  let type =
35
37
  (tree
36
- .map((schema, _index, siblings) =>
38
+ .map((current, _index, siblings) =>
37
39
  parse(
38
- { parent: undefined, current: schema, siblings },
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 (schema && isKeyword(schema, schemaKeywords.schema) && schema.args.type !== 'object') {
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
- description: description ? transformers.jsStringEscape(description) : undefined,
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