@kubb/plugin-ts 5.0.0-beta.4 → 5.0.0-beta.42
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/README.md +39 -22
- package/dist/index.cjs +432 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +84 -62
- package/dist/index.js +427 -125
- package/dist/index.js.map +1 -1
- package/extension.yaml +713 -265
- package/package.json +10 -12
- package/src/components/Enum.tsx +3 -3
- package/src/factory.ts +54 -25
- package/src/generators/typeGenerator.tsx +100 -39
- package/src/plugin.ts +20 -21
- package/src/printers/functionPrinter.ts +2 -2
- package/src/printers/printerTs.ts +31 -30
- package/src/resolvers/resolverTs.ts +28 -25
- package/src/types.ts +44 -37
- package/src/utils.ts +23 -13
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { ast } from '@kubb/core'
|
|
2
|
-
import {
|
|
2
|
+
import { parserTs } from '@kubb/parser-ts'
|
|
3
3
|
import type ts from 'typescript'
|
|
4
4
|
import { ENUM_TYPES_WITH_KEY_SUFFIX, OPTIONAL_ADDS_QUESTION_TOKEN, OPTIONAL_ADDS_UNDEFINED } from '../constants.ts'
|
|
5
5
|
import * as factory from '../factory.ts'
|
|
6
6
|
import type { PluginTs, ResolverTs } from '../types.ts'
|
|
7
7
|
import { buildPropertyJSDocComments } from '../utils.ts'
|
|
8
8
|
|
|
9
|
+
function isNonNullable<T>(value: T | null | undefined): value is T {
|
|
10
|
+
return value !== null && value !== undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
9
13
|
/**
|
|
10
14
|
* Partial map of node-type overrides for the TypeScript printer.
|
|
11
15
|
*
|
|
@@ -85,7 +89,7 @@ export type PrinterTsOptions = {
|
|
|
85
89
|
* Properties to exclude using `Omit<Type, Keys>`.
|
|
86
90
|
* Forces type alias syntax regardless of `syntaxType` setting.
|
|
87
91
|
*/
|
|
88
|
-
keysToOmit?: Array<string>
|
|
92
|
+
keysToOmit?: Array<string> | null
|
|
89
93
|
/**
|
|
90
94
|
* Transforms raw schema names into valid TypeScript identifiers.
|
|
91
95
|
*/
|
|
@@ -163,7 +167,7 @@ export const printerTs = ast.definePrinter<PrinterTs>((options) => {
|
|
|
163
167
|
time: factory.dateOrStringNode,
|
|
164
168
|
ref(node) {
|
|
165
169
|
if (!node.name) {
|
|
166
|
-
return
|
|
170
|
+
return null
|
|
167
171
|
}
|
|
168
172
|
// Parser-generated refs (with $ref) carry raw schema names that need resolving.
|
|
169
173
|
// Use the canonical name from the $ref path — node.name may have been overridden
|
|
@@ -191,7 +195,7 @@ export const printerTs = ast.definePrinter<PrinterTs>((options) => {
|
|
|
191
195
|
const literalNodes = values
|
|
192
196
|
.filter((v): v is string | number | boolean => v !== null && v !== undefined)
|
|
193
197
|
.map((value) => factory.constToTypeNode(value, typeof value as 'string' | 'number' | 'boolean'))
|
|
194
|
-
.filter(
|
|
198
|
+
.filter(isNonNullable)
|
|
195
199
|
|
|
196
200
|
return factory.createUnionDeclaration({ withParentheses: true, nodes: literalNodes }) ?? undefined
|
|
197
201
|
}
|
|
@@ -224,7 +228,7 @@ export const printerTs = ast.definePrinter<PrinterTs>((options) => {
|
|
|
224
228
|
|
|
225
229
|
return this.transform(m)
|
|
226
230
|
})
|
|
227
|
-
.filter(
|
|
231
|
+
.filter(isNonNullable)
|
|
228
232
|
|
|
229
233
|
return factory.createUnionDeclaration({ withParentheses: true, nodes: memberNodes }) ?? undefined
|
|
230
234
|
}
|
|
@@ -232,15 +236,15 @@ export const printerTs = ast.definePrinter<PrinterTs>((options) => {
|
|
|
232
236
|
return factory.createUnionDeclaration({ withParentheses: true, nodes: factory.buildMemberNodes(members, this.transform) }) ?? undefined
|
|
233
237
|
},
|
|
234
238
|
intersection(node) {
|
|
235
|
-
return factory.createIntersectionDeclaration({ withParentheses: true, nodes: factory.buildMemberNodes(node.members, this.transform) }) ??
|
|
239
|
+
return factory.createIntersectionDeclaration({ withParentheses: true, nodes: factory.buildMemberNodes(node.members, this.transform) }) ?? null
|
|
236
240
|
},
|
|
237
241
|
array(node) {
|
|
238
|
-
const itemNodes = (node.items ?? []).map((item) => this.transform(item)).filter(
|
|
242
|
+
const itemNodes = (node.items ?? []).map((item) => this.transform(item)).filter(isNonNullable)
|
|
239
243
|
|
|
240
|
-
return factory.createArrayDeclaration({ nodes: itemNodes, arrayType: this.options.arrayType }) ??
|
|
244
|
+
return factory.createArrayDeclaration({ nodes: itemNodes, arrayType: this.options.arrayType }) ?? null
|
|
241
245
|
},
|
|
242
246
|
tuple(node) {
|
|
243
|
-
return factory.buildTupleNode(node, this.transform)
|
|
247
|
+
return factory.buildTupleNode(node, this.transform) ?? null
|
|
244
248
|
},
|
|
245
249
|
object(node) {
|
|
246
250
|
const { transform, options } = this
|
|
@@ -275,36 +279,33 @@ export const printerTs = ast.definePrinter<PrinterTs>((options) => {
|
|
|
275
279
|
print(node) {
|
|
276
280
|
const { name, syntaxType = 'type', description, keysToOmit } = this.options
|
|
277
281
|
|
|
278
|
-
|
|
279
|
-
if (!
|
|
282
|
+
const transformed = this.transform(node)
|
|
283
|
+
if (!transformed) return null
|
|
280
284
|
|
|
281
285
|
// For ref nodes, structural metadata lives on node.schema rather than the ref node itself.
|
|
282
286
|
const meta = ast.syncSchemaRef(node)
|
|
283
287
|
|
|
284
288
|
// Without name, apply modifiers inline and return.
|
|
285
289
|
if (!name) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
return safePrint(base)
|
|
290
|
+
const withNullable = meta.nullable ? factory.createUnionDeclaration({ nodes: [transformed, factory.keywordTypeNodes.null] }) : transformed
|
|
291
|
+
const result =
|
|
292
|
+
(meta.nullish || meta.optional) && addsUndefined
|
|
293
|
+
? factory.createUnionDeclaration({ nodes: [withNullable, factory.keywordTypeNodes.undefined] })
|
|
294
|
+
: withNullable
|
|
295
|
+
return parserTs.print(result)
|
|
293
296
|
}
|
|
294
297
|
|
|
295
298
|
// When keysToOmit is present, wrap with Omit first, then apply nullable/optional
|
|
296
299
|
// modifiers so they are not swallowed by NonNullable inside createOmitDeclaration.
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
inner = factory.createUnionDeclaration({ nodes: [inner, factory.keywordTypeNodes.undefined] })
|
|
307
|
-
}
|
|
300
|
+
const inner = (() => {
|
|
301
|
+
const omitted: ts.TypeNode = keysToOmit?.length
|
|
302
|
+
? factory.createOmitDeclaration({ keys: keysToOmit, type: transformed, nonNullable: true })
|
|
303
|
+
: transformed
|
|
304
|
+
const withNullable = meta.nullable ? factory.createUnionDeclaration({ nodes: [omitted, factory.keywordTypeNodes.null] }) : omitted
|
|
305
|
+
// For named type declarations (type aliases), optional/nullish always produces | undefined
|
|
306
|
+
// regardless of optionalType — the questionToken ? modifier only applies to object properties.
|
|
307
|
+
return meta.nullish || meta.optional ? factory.createUnionDeclaration({ nodes: [withNullable, factory.keywordTypeNodes.undefined] }) : withNullable
|
|
308
|
+
})()
|
|
308
309
|
|
|
309
310
|
const useTypeGeneration = syntaxType === 'type' || inner.kind === factory.syntaxKind.union || !!keysToOmit?.length
|
|
310
311
|
|
|
@@ -319,7 +320,7 @@ export const printerTs = ast.definePrinter<PrinterTs>((options) => {
|
|
|
319
320
|
}),
|
|
320
321
|
})
|
|
321
322
|
|
|
322
|
-
return
|
|
323
|
+
return parserTs.print(typeNode)
|
|
323
324
|
},
|
|
324
325
|
}
|
|
325
326
|
})
|
|
@@ -1,66 +1,69 @@
|
|
|
1
|
-
import { pascalCase } from '@internals/utils'
|
|
1
|
+
import { ensureValidVarName, pascalCase } from '@internals/utils'
|
|
2
2
|
import { defineResolver } from '@kubb/core'
|
|
3
3
|
import type { PluginTs } from '../types.ts'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|
|
7
|
+
* for every generated TypeScript type. Import this in other plugins that need
|
|
8
|
+
* to reference the exact names `plugin-ts` produces without duplicating the
|
|
9
|
+
* casing/file-layout rules.
|
|
9
10
|
*
|
|
10
|
-
* The `default` method is
|
|
11
|
-
*
|
|
11
|
+
* The `default` method is supplied by `defineResolver`. It uses PascalCase for
|
|
12
|
+
* type names and PascalCase-with-isFile for files.
|
|
12
13
|
*
|
|
13
|
-
* @example
|
|
14
|
+
* @example Resolve a type and file name
|
|
14
15
|
* ```ts
|
|
15
|
-
* import {
|
|
16
|
+
* import { resolverTs } from '@kubb/plugin-ts'
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* resolverTs.default('list pets', 'type') // 'ListPets'
|
|
19
|
+
* resolverTs.resolvePathName('list pets', 'file') // 'ListPets'
|
|
20
|
+
* resolverTs.resolveResponseStatusName(node, 200) // 'ListPetsStatus200'
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
|
-
export const resolverTs = defineResolver<PluginTs>((
|
|
23
|
+
export const resolverTs = defineResolver<PluginTs>(() => {
|
|
23
24
|
return {
|
|
24
25
|
name: 'default',
|
|
25
26
|
pluginName: 'plugin-ts',
|
|
26
27
|
default(name, type) {
|
|
27
|
-
|
|
28
|
+
const resolved = pascalCase(name, { isFile: type === 'file' })
|
|
29
|
+
return type === 'file' ? resolved : ensureValidVarName(resolved)
|
|
28
30
|
},
|
|
29
31
|
resolveTypeName(name) {
|
|
30
|
-
return pascalCase(name)
|
|
32
|
+
return ensureValidVarName(pascalCase(name))
|
|
31
33
|
},
|
|
32
34
|
resolvePathName(name, type) {
|
|
33
|
-
|
|
35
|
+
const resolved = pascalCase(name, { isFile: type === 'file' })
|
|
36
|
+
return type === 'file' ? resolved : ensureValidVarName(resolved)
|
|
34
37
|
},
|
|
35
38
|
resolveParamName(node, param) {
|
|
36
|
-
return
|
|
39
|
+
return this.resolveTypeName(`${node.operationId} ${param.in} ${param.name}`)
|
|
37
40
|
},
|
|
38
41
|
resolveResponseStatusName(node, statusCode) {
|
|
39
|
-
return
|
|
42
|
+
return this.resolveTypeName(`${node.operationId} Status ${statusCode}`)
|
|
40
43
|
},
|
|
41
44
|
resolveDataName(node) {
|
|
42
|
-
return
|
|
45
|
+
return this.resolveTypeName(`${node.operationId} Data`)
|
|
43
46
|
},
|
|
44
47
|
resolveRequestConfigName(node) {
|
|
45
|
-
return
|
|
48
|
+
return this.resolveTypeName(`${node.operationId} RequestConfig`)
|
|
46
49
|
},
|
|
47
50
|
resolveResponsesName(node) {
|
|
48
|
-
return
|
|
51
|
+
return this.resolveTypeName(`${node.operationId} Responses`)
|
|
49
52
|
},
|
|
50
53
|
resolveResponseName(node) {
|
|
51
|
-
return
|
|
54
|
+
return this.resolveTypeName(`${node.operationId} Response`)
|
|
52
55
|
},
|
|
53
56
|
resolveEnumKeyName(node, enumTypeSuffix = 'key') {
|
|
54
|
-
return `${
|
|
57
|
+
return `${this.resolveTypeName(node.name ?? '')}${enumTypeSuffix}`
|
|
55
58
|
},
|
|
56
59
|
resolvePathParamsName(node, param) {
|
|
57
|
-
return
|
|
60
|
+
return this.resolveParamName(node, param)
|
|
58
61
|
},
|
|
59
62
|
resolveQueryParamsName(node, param) {
|
|
60
|
-
return
|
|
63
|
+
return this.resolveParamName(node, param)
|
|
61
64
|
},
|
|
62
65
|
resolveHeaderParamsName(node, param) {
|
|
63
|
-
return
|
|
66
|
+
return this.resolveParamName(node, param)
|
|
64
67
|
},
|
|
65
68
|
}
|
|
66
69
|
})
|
package/src/types.ts
CHANGED
|
@@ -115,7 +115,7 @@ type EnumTypeOptions =
|
|
|
115
115
|
/**
|
|
116
116
|
* Suffix appended to the generated type alias name.
|
|
117
117
|
*
|
|
118
|
-
* Only affects the type alias
|
|
118
|
+
* Only affects the type alias; the const object name is unchanged.
|
|
119
119
|
*
|
|
120
120
|
* @default 'Key'
|
|
121
121
|
* @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
|
|
@@ -172,81 +172,89 @@ type EnumTypeOptions =
|
|
|
172
172
|
enumTypeSuffix?: never
|
|
173
173
|
/**
|
|
174
174
|
* `enumKeyCasing` has no effect for this `enumType`.
|
|
175
|
-
* Literal and inlineLiteral modes emit only values
|
|
175
|
+
* Literal and inlineLiteral modes emit only values; keys are discarded entirely.
|
|
176
176
|
*/
|
|
177
177
|
enumKeyCasing?: never
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
export type Options = {
|
|
181
181
|
/**
|
|
182
|
-
*
|
|
183
|
-
*
|
|
182
|
+
* Where the generated `.ts` files are written and how they are exported.
|
|
183
|
+
*
|
|
184
|
+
* @default { path: 'types', barrel: { type: 'named' } }
|
|
184
185
|
*/
|
|
185
186
|
output?: Output
|
|
186
187
|
/**
|
|
187
|
-
*
|
|
188
|
-
*
|
|
188
|
+
* Media type read from the OpenAPI spec when an operation defines several.
|
|
189
|
+
* Defaults to the first JSON-compatible media type Kubb finds.
|
|
189
190
|
*/
|
|
190
191
|
contentType?: 'application/json' | (string & {})
|
|
191
192
|
/**
|
|
192
|
-
*
|
|
193
|
+
* Split generated files into subfolders based on the operation's tag.
|
|
193
194
|
*/
|
|
194
195
|
group?: Group
|
|
195
196
|
/**
|
|
196
|
-
*
|
|
197
|
+
* Skip operations matching at least one entry in the list.
|
|
197
198
|
*/
|
|
198
199
|
exclude?: Array<Exclude>
|
|
199
200
|
/**
|
|
200
|
-
*
|
|
201
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
201
202
|
*/
|
|
202
203
|
include?: Array<Include>
|
|
203
204
|
/**
|
|
204
|
-
*
|
|
205
|
+
* Apply a different options object to operations matching a pattern.
|
|
205
206
|
*/
|
|
206
207
|
override?: Array<Override<ResolvedOptions>>
|
|
207
208
|
/**
|
|
208
|
-
*
|
|
209
|
-
* - 'type'
|
|
210
|
-
* - 'interface'
|
|
209
|
+
* Whether object schemas are emitted as `type` aliases or `interface` declarations.
|
|
210
|
+
* - `'type'` emits closed type aliases. Safer default for generated code.
|
|
211
|
+
* - `'interface'` emits interfaces. Useful when consumers rely on declaration merging.
|
|
212
|
+
*
|
|
211
213
|
* @default 'type'
|
|
214
|
+
* @see https://www.totaltypescript.com/type-vs-interface-which-should-you-use
|
|
212
215
|
*/
|
|
213
216
|
syntaxType?: 'type' | 'interface'
|
|
214
217
|
/**
|
|
215
|
-
*
|
|
216
|
-
* - 'questionToken'
|
|
217
|
-
* - 'undefined'
|
|
218
|
-
* - 'questionTokenAndUndefined'
|
|
218
|
+
* How optional properties are written in generated types.
|
|
219
|
+
* - `'questionToken'` — `type?: string`. The property may be missing.
|
|
220
|
+
* - `'undefined'` — `type: string | undefined`. Required to exist, may be `undefined`.
|
|
221
|
+
* - `'questionTokenAndUndefined'` — `type?: string | undefined`. Strictest.
|
|
222
|
+
*
|
|
219
223
|
* @default 'questionToken'
|
|
224
|
+
* @note Pick `'questionTokenAndUndefined'` when `exactOptionalPropertyTypes` is on in `tsconfig.json`.
|
|
220
225
|
*/
|
|
221
226
|
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined'
|
|
222
227
|
/**
|
|
223
|
-
*
|
|
224
|
-
* - '
|
|
225
|
-
* - '
|
|
228
|
+
* Syntax used for array types.
|
|
229
|
+
* - `'array'` — `Type[]`. Shorter.
|
|
230
|
+
* - `'generic'` — `Array<Type>`. More readable for complex element types.
|
|
231
|
+
*
|
|
226
232
|
* @default 'array'
|
|
227
233
|
*/
|
|
228
234
|
arrayType?: 'generic' | 'array'
|
|
229
235
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* @note
|
|
236
|
+
* Rename properties inside `PathParams`, `QueryParams`, and `HeaderParams` types.
|
|
237
|
+
* Response and request body types are not affected.
|
|
238
|
+
*
|
|
239
|
+
* @note Every plugin that touches operation parameters must use the same value.
|
|
234
240
|
*/
|
|
235
241
|
paramsCasing?: 'camelcase'
|
|
236
242
|
/**
|
|
237
|
-
*
|
|
243
|
+
* Custom generators that run alongside the built-in TypeScript generators.
|
|
238
244
|
*/
|
|
239
245
|
generators?: Array<Generator<PluginTs>>
|
|
240
246
|
/**
|
|
241
|
-
* Override
|
|
242
|
-
*
|
|
247
|
+
* Override how names and file paths are built for generated symbols.
|
|
248
|
+
* Methods you omit fall back to the default `resolverTs`. `this` is bound to the
|
|
249
|
+
* full resolver, so `this.default(name, 'function')` delegates to the built-in
|
|
250
|
+
* implementation.
|
|
243
251
|
*/
|
|
244
252
|
resolver?: Partial<ResolverTs> & ThisType<ResolverTs>
|
|
245
253
|
/**
|
|
246
|
-
* AST visitor applied to each schema
|
|
247
|
-
*
|
|
254
|
+
* AST visitor applied to each schema or operation node before printing.
|
|
255
|
+
* Methods you omit fall back to the preset transformer.
|
|
248
256
|
*
|
|
249
|
-
* @example
|
|
257
|
+
* @example Drop writeOnly properties from response types
|
|
250
258
|
* ```ts
|
|
251
259
|
* transformer: {
|
|
252
260
|
* property(node) {
|
|
@@ -257,18 +265,17 @@ export type Options = {
|
|
|
257
265
|
*/
|
|
258
266
|
transformer?: ast.Visitor
|
|
259
267
|
/**
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* built-in handler for that type. Use `this.transform` to recurse into nested schema nodes.
|
|
268
|
+
* Replace the TypeScript handler for a specific schema type (`'integer'`, `'date'`, ...).
|
|
269
|
+
* Each handler returns a TypeScript AST node for that schema type. Use `this.transform`
|
|
270
|
+
* to recurse into nested schema nodes.
|
|
264
271
|
*
|
|
265
|
-
* @example
|
|
272
|
+
* @example Use the JavaScript `Date` object for date schemas
|
|
266
273
|
* ```ts
|
|
267
274
|
* import ts from 'typescript'
|
|
268
275
|
* pluginTs({
|
|
269
276
|
* printer: {
|
|
270
277
|
* nodes: {
|
|
271
|
-
* date(
|
|
278
|
+
* date() {
|
|
272
279
|
* return ts.factory.createTypeReferenceNode('Date', [])
|
|
273
280
|
* },
|
|
274
281
|
* },
|
|
@@ -286,7 +293,7 @@ type ResolvedOptions = {
|
|
|
286
293
|
exclude: Array<Exclude>
|
|
287
294
|
include: Array<Include> | undefined
|
|
288
295
|
override: Array<Override<ResolvedOptions>>
|
|
289
|
-
group: Group |
|
|
296
|
+
group: Group | null
|
|
290
297
|
enumType: NonNullable<Options['enumType']>
|
|
291
298
|
enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>
|
|
292
299
|
enumKeyCasing: EnumKeyCasing
|
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsStringEscape, stringify } from '@internals/utils'
|
|
2
|
+
import { getOperationParameters } from '@internals/shared'
|
|
2
3
|
import { ast } from '@kubb/core'
|
|
3
4
|
import type { ResolverTs } from './types.ts'
|
|
4
5
|
|
|
@@ -14,20 +15,31 @@ export function buildPropertyJSDocComments(schema: ast.SchemaNode): Array<string
|
|
|
14
15
|
|
|
15
16
|
const isArray = meta?.primitive === 'array'
|
|
16
17
|
|
|
18
|
+
const hasDescription = meta && 'description' in meta && meta.description
|
|
19
|
+
|
|
20
|
+
const formatComment =
|
|
21
|
+
meta && 'format' in meta && meta.format
|
|
22
|
+
? hasDescription
|
|
23
|
+
? // Empty line between description and format
|
|
24
|
+
[' ', `Format: \`${meta.format}\``]
|
|
25
|
+
: ['@description', `Format: \`${meta.format}\``]
|
|
26
|
+
: []
|
|
27
|
+
|
|
17
28
|
return [
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
hasDescription ? `@description ${jsStringEscape(meta.description)}` : null,
|
|
30
|
+
...formatComment,
|
|
31
|
+
meta && 'deprecated' in meta && meta.deprecated ? '@deprecated' : null,
|
|
20
32
|
// minItems/maxItems on arrays should not be emitted as @minLength/@maxLength
|
|
21
|
-
!isArray && meta && 'min' in meta && meta.min !== undefined ? `@minLength ${meta.min}` :
|
|
22
|
-
!isArray && meta && 'max' in meta && meta.max !== undefined ? `@maxLength ${meta.max}` :
|
|
23
|
-
meta && 'pattern' in meta && meta.pattern ? `@pattern ${meta.pattern}` :
|
|
33
|
+
!isArray && meta && 'min' in meta && meta.min !== undefined ? `@minLength ${meta.min}` : null,
|
|
34
|
+
!isArray && meta && 'max' in meta && meta.max !== undefined ? `@maxLength ${meta.max}` : null,
|
|
35
|
+
meta && 'pattern' in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
|
|
24
36
|
meta && 'default' in meta && meta.default !== undefined
|
|
25
37
|
? `@default ${'primitive' in meta && meta.primitive === 'string' ? stringify(meta.default as string) : meta.default}`
|
|
26
|
-
:
|
|
27
|
-
meta && 'example' in meta && meta.example !== undefined ? `@example ${meta.example}` :
|
|
38
|
+
: null,
|
|
39
|
+
meta && 'example' in meta && meta.example !== undefined ? `@example ${meta.example}` : null,
|
|
28
40
|
meta && 'primitive' in meta && meta.primitive
|
|
29
|
-
? [`@type ${meta.primitive}`, 'optional' in schema && schema.optional ? ' | undefined' :
|
|
30
|
-
:
|
|
41
|
+
? [`@type ${meta.primitive}`, 'optional' in schema && schema.optional ? ' | undefined' : null].filter(Boolean).join('')
|
|
42
|
+
: null,
|
|
31
43
|
].filter(Boolean)
|
|
32
44
|
}
|
|
33
45
|
|
|
@@ -57,9 +69,7 @@ export function buildParams(node: ast.OperationNode, { params, resolver }: Build
|
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
export function buildData(node: ast.OperationNode, { resolver }: BuildOperationSchemaOptions): ast.SchemaNode {
|
|
60
|
-
const pathParams
|
|
61
|
-
const queryParams = node.parameters.filter((p) => p.in === 'query')
|
|
62
|
-
const headerParams = node.parameters.filter((p) => p.in === 'header')
|
|
72
|
+
const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node)
|
|
63
73
|
|
|
64
74
|
return ast.createSchema({
|
|
65
75
|
type: 'object',
|
|
@@ -117,7 +127,7 @@ export function buildResponses(node: ast.OperationNode, { resolver }: BuildOpera
|
|
|
117
127
|
}
|
|
118
128
|
|
|
119
129
|
export function buildResponseUnion(node: ast.OperationNode, { resolver }: BuildOperationSchemaOptions): ast.SchemaNode | null {
|
|
120
|
-
const responsesWithSchema = node.responses.filter((res) => res.schema)
|
|
130
|
+
const responsesWithSchema = node.responses.filter((res) => res.content?.some((entry) => entry.schema))
|
|
121
131
|
|
|
122
132
|
if (responsesWithSchema.length === 0) {
|
|
123
133
|
return null
|
|
File without changes
|