@kubb/plugin-ts 3.3.2 → 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/index.cjs CHANGED
@@ -1,17 +1,17 @@
1
1
  'use strict';
2
2
 
3
- var chunk663J2WTL_cjs = require('./chunk-663J2WTL.cjs');
4
- require('./chunk-PNGMUZT2.cjs');
3
+ var chunkJZIXHFCA_cjs = require('./chunk-JZIXHFCA.cjs');
4
+ require('./chunk-YKKU2PFK.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "pluginTs", {
9
9
  enumerable: true,
10
- get: function () { return chunk663J2WTL_cjs.pluginTs; }
10
+ get: function () { return chunkJZIXHFCA_cjs.pluginTs; }
11
11
  });
12
12
  Object.defineProperty(exports, "pluginTsName", {
13
13
  enumerable: true,
14
- get: function () { return chunk663J2WTL_cjs.pluginTsName; }
14
+ get: function () { return chunkJZIXHFCA_cjs.pluginTsName; }
15
15
  });
16
16
  //# sourceMappingURL=index.cjs.map
17
17
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { pluginTs, pluginTsName } from './chunk-XCUOQALP.js';
2
- import './chunk-2FMMBGL3.js';
1
+ export { pluginTs, pluginTsName } from './chunk-TFCUDXXU.js';
2
+ import './chunk-U7IYQJBH.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.2",
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.2",
62
- "@kubb/fs": "3.3.2",
63
- "@kubb/oas": "3.3.2",
64
- "@kubb/parser-ts": "3.3.2",
65
- "@kubb/plugin-oas": "3.3.2",
66
- "@kubb/react": "3.3.2"
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.16",
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.2",
74
- "@kubb/config-tsup": "3.3.2"
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"
@@ -1,7 +1,6 @@
1
1
  import { File, Type } from '@kubb/react'
2
2
 
3
3
  import type { OasTypes } from '@kubb/oas'
4
- import type { ReactNode } from 'react'
5
4
 
6
5
  type Props = {
7
6
  /**
@@ -12,7 +11,7 @@ type Props = {
12
11
  api: OasTypes.OASDocument
13
12
  }
14
13
 
15
- export function OasType({ name, typeName, api }: Props): ReactNode {
14
+ export function OasType({ name, typeName, api }: Props) {
16
15
  return (
17
16
  <>
18
17
  <File.Source name={name} isExportable isIndexable>
@@ -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
 
@@ -119,7 +129,8 @@ export function Type({ name, typedName, tree, keysToOmit, optionalType, syntaxTy
119
129
  return (
120
130
  <Fragment>
121
131
  {enums.map(({ name, nameNode, typeName, typeNode }, index) => (
122
- <Fragment key={[name, nameNode].join('-')}>
132
+ // biome-ignore lint/correctness/useJsxKeyInIterable: <explanation>
133
+ <Fragment>
123
134
  {nameNode && (
124
135
  <File.Source name={name} isExportable isIndexable>
125
136
  {print([nameNode])}
@@ -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