@kubb/ast 5.0.0-alpha.53 → 5.0.0-alpha.55
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 +9 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +28 -13
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/mocks.ts +1 -1
- package/src/nodes/operation.ts +28 -13
- package/src/utils.ts +1 -1
- package/src/visitor.ts +5 -2
package/package.json
CHANGED
package/src/mocks.ts
CHANGED
|
@@ -162,7 +162,7 @@ export function buildFixture(): InputNode {
|
|
|
162
162
|
method: 'POST',
|
|
163
163
|
path: '/pets',
|
|
164
164
|
tags: ['pets'],
|
|
165
|
-
requestBody: { schema: createSchema({ type: 'ref', ref: 'NewPet' }) },
|
|
165
|
+
requestBody: { content: [{ contentType: 'application/json', schema: createSchema({ type: 'ref', ref: 'NewPet' }) }] },
|
|
166
166
|
responses: [
|
|
167
167
|
createResponse({
|
|
168
168
|
statusCode: '201',
|
package/src/nodes/operation.ts
CHANGED
|
@@ -68,26 +68,41 @@ export type OperationNode = BaseNode & {
|
|
|
68
68
|
* Human-readable request body description.
|
|
69
69
|
*/
|
|
70
70
|
description?: string
|
|
71
|
-
/**
|
|
72
|
-
* Request body schema.
|
|
73
|
-
* For OpenAPI, this is the schema from the first `content` entry.
|
|
74
|
-
*/
|
|
75
|
-
schema?: SchemaNode
|
|
76
|
-
/**
|
|
77
|
-
* Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
|
|
78
|
-
* Set when a referenced schema has `readOnly` fields that should be omitted in request types.
|
|
79
|
-
*/
|
|
80
|
-
keysToOmit?: Array<string>
|
|
81
71
|
/**
|
|
82
72
|
* Whether the request body is required (`requestBody.required: true` in the spec).
|
|
83
73
|
* When `false` or absent, the generated `data` parameter should be optional.
|
|
84
74
|
*/
|
|
85
75
|
required?: boolean
|
|
86
76
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
77
|
+
* All available content type entries for this request body.
|
|
78
|
+
*
|
|
79
|
+
* When the adapter `contentType` option is set, this array contains exactly one entry for
|
|
80
|
+
* that content type. Otherwise it contains one entry per content type declared in the spec,
|
|
81
|
+
* so that plugins can generate code for every variant (e.g. separate hooks for
|
|
82
|
+
* `application/json` and `multipart/form-data`).
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* // spec has both application/json and multipart/form-data
|
|
87
|
+
* requestBody.content[0].contentType // 'application/json'
|
|
88
|
+
* requestBody.content[1].contentType // 'multipart/form-data'
|
|
89
|
+
* ```
|
|
89
90
|
*/
|
|
90
|
-
|
|
91
|
+
content?: Array<{
|
|
92
|
+
/**
|
|
93
|
+
* The content type for this entry (e.g. `'application/json'`).
|
|
94
|
+
*/
|
|
95
|
+
contentType: string
|
|
96
|
+
/**
|
|
97
|
+
* Request body schema for this content type.
|
|
98
|
+
*/
|
|
99
|
+
schema?: SchemaNode
|
|
100
|
+
/**
|
|
101
|
+
* Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
|
|
102
|
+
* Set when a referenced schema has `readOnly` fields that should be omitted in request types.
|
|
103
|
+
*/
|
|
104
|
+
keysToOmit?: Array<string>
|
|
105
|
+
}>
|
|
91
106
|
}
|
|
92
107
|
/**
|
|
93
108
|
* Operation responses.
|
package/src/utils.ts
CHANGED
|
@@ -340,7 +340,7 @@ export function createOperationParams(node: OperationNode, options: CreateOperat
|
|
|
340
340
|
const queryParams = casedParams.filter((p) => p.in === 'query')
|
|
341
341
|
const headerParams = casedParams.filter((p) => p.in === 'header')
|
|
342
342
|
|
|
343
|
-
const bodyType = node.requestBody?.schema ? wrapType(resolver?.resolveDataName(node) ?? 'unknown') : undefined
|
|
343
|
+
const bodyType = node.requestBody?.content?.[0]?.schema ? wrapType(resolver?.resolveDataName(node) ?? 'unknown') : undefined
|
|
344
344
|
const bodyRequired = node.requestBody?.required ?? false
|
|
345
345
|
|
|
346
346
|
const queryGroupType = resolver
|
package/src/visitor.ts
CHANGED
|
@@ -272,7 +272,7 @@ function getChildren(node: Node, recurse: boolean): Array<Node> {
|
|
|
272
272
|
case 'Output':
|
|
273
273
|
return []
|
|
274
274
|
case 'Operation':
|
|
275
|
-
return [...node.parameters, ...(node.requestBody?.schema ? [
|
|
275
|
+
return [...node.parameters, ...(node.requestBody?.content?.flatMap((c) => (c.schema ? [c.schema] : [])) ?? []), ...node.responses]
|
|
276
276
|
case 'Schema': {
|
|
277
277
|
const children: Array<Node> = []
|
|
278
278
|
|
|
@@ -440,7 +440,10 @@ export function transform(node: Node, options: TransformOptions): Node {
|
|
|
440
440
|
requestBody: op.requestBody
|
|
441
441
|
? {
|
|
442
442
|
...op.requestBody,
|
|
443
|
-
|
|
443
|
+
content: op.requestBody.content?.map((c) => ({
|
|
444
|
+
...c,
|
|
445
|
+
schema: c.schema ? transform(c.schema, { ...options, parent: op }) : undefined,
|
|
446
|
+
})),
|
|
444
447
|
}
|
|
445
448
|
: undefined,
|
|
446
449
|
responses: op.responses.map((r) => transform(r, { ...options, parent: op })),
|