@kubb/ast 5.0.0-beta.63 → 5.0.0-beta.64

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.
Files changed (69) hide show
  1. package/dist/{defineMacro-Shz8f6SG.js → defineMacro-B76LsJwO.js} +4 -4
  2. package/dist/{defineMacro-Shz8f6SG.js.map → defineMacro-B76LsJwO.js.map} +1 -1
  3. package/dist/{defineMacro-BATi7xoC.d.ts → defineMacro-B7qm3zTd.d.ts} +3 -3
  4. package/dist/factory-wJLzHeXT.d.ts +27 -0
  5. package/dist/factory.d.ts +3 -27
  6. package/dist/factory.js +2 -2
  7. package/dist/{index-B9cc8MBS.d.ts → index-BKD4drsX.d.ts} +2 -2
  8. package/dist/index.cjs +54 -2
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +24 -21
  11. package/dist/index.js +54 -8
  12. package/dist/index.js.map +1 -1
  13. package/dist/macros.d.ts +2 -2
  14. package/dist/macros.js +4 -4
  15. package/dist/{operationParams-k5CKwSWZ.d.ts → operationParams-ByVfpYr7.d.ts} +3 -3
  16. package/dist/{refs-BjNDuCBD.js → refs-Dx6U5LoE.js} +3 -3
  17. package/dist/{refs-BjNDuCBD.js.map → refs-Dx6U5LoE.js.map} +1 -1
  18. package/dist/{schema-Cbnxmz4b.js → schema-YNbOtTCM.js} +2 -2
  19. package/dist/{schema-Cbnxmz4b.js.map → schema-YNbOtTCM.js.map} +1 -1
  20. package/dist/{types-BB_xgRJ3.d.ts → types-BP9BZoq-.d.ts} +8 -8
  21. package/dist/types.d.ts +5 -5
  22. package/dist/{utils-DaXkewb1.js → utils-BJi0y-xg.js} +4 -4
  23. package/dist/{utils-DaXkewb1.js.map → utils-BJi0y-xg.js.map} +1 -1
  24. package/dist/utils.d.ts +3 -3
  25. package/dist/utils.js +3 -3
  26. package/package.json +1 -2
  27. package/src/constants.ts +0 -150
  28. package/src/defineMacro.ts +0 -139
  29. package/src/defineNode.ts +0 -102
  30. package/src/definePrinter.ts +0 -258
  31. package/src/dialect.ts +0 -86
  32. package/src/factory.ts +0 -44
  33. package/src/guards.ts +0 -28
  34. package/src/index.ts +0 -13
  35. package/src/infer.ts +0 -132
  36. package/src/macros/index.ts +0 -3
  37. package/src/macros/macroDiscriminatorEnum.ts +0 -50
  38. package/src/macros/macroEnumName.ts +0 -33
  39. package/src/macros/macroSimplifyUnion.ts +0 -60
  40. package/src/nodes/base.ts +0 -49
  41. package/src/nodes/code.ts +0 -355
  42. package/src/nodes/content.ts +0 -51
  43. package/src/nodes/file.ts +0 -380
  44. package/src/nodes/function.ts +0 -283
  45. package/src/nodes/index.ts +0 -93
  46. package/src/nodes/input.ts +0 -144
  47. package/src/nodes/operation.ts +0 -168
  48. package/src/nodes/output.ts +0 -49
  49. package/src/nodes/parameter.ts +0 -71
  50. package/src/nodes/property.ts +0 -67
  51. package/src/nodes/requestBody.ts +0 -54
  52. package/src/nodes/response.ts +0 -173
  53. package/src/nodes/schema.ts +0 -732
  54. package/src/optionality.ts +0 -15
  55. package/src/registry.ts +0 -75
  56. package/src/signature.ts +0 -207
  57. package/src/types.ts +0 -8
  58. package/src/utils/codegen.ts +0 -103
  59. package/src/utils/extractStringsFromNodes.ts +0 -35
  60. package/src/utils/fileMerge.ts +0 -183
  61. package/src/utils/index.ts +0 -11
  62. package/src/utils/operationParams.ts +0 -353
  63. package/src/utils/refs.ts +0 -134
  64. package/src/utils/schemaGraph.ts +0 -177
  65. package/src/utils/schemaMerge.ts +0 -34
  66. package/src/utils/schemaTraversal.ts +0 -86
  67. package/src/utils/strings.ts +0 -139
  68. package/src/visitor.ts +0 -519
  69. /package/dist/{chunk-CNktS9qV.js → rolldown-runtime-CNktS9qV.js} +0 -0
@@ -1,93 +0,0 @@
1
- import type { ArrowFunctionNode, ConstNode, FunctionNode, TypeNode } from './code.ts'
2
- import type { ContentNode } from './content.ts'
3
- import type { ExportNode, FileNode, ImportNode, SourceNode } from './file.ts'
4
- import type { FunctionParamNode } from './function.ts'
5
- import type { InputNode } from './input.ts'
6
- import type { OperationNode } from './operation.ts'
7
- import type { OutputNode } from './output.ts'
8
- import type { ParameterNode } from './parameter.ts'
9
- import type { PropertyNode } from './property.ts'
10
- import type { RequestBodyNode } from './requestBody.ts'
11
- import type { ResponseNode } from './response.ts'
12
- import type { SchemaNode } from './schema.ts'
13
-
14
- export type { NodeKind } from './base.ts'
15
- export type { ArrowFunctionNode, BreakNode, CodeNode, ConstNode, FunctionNode, JSDocNode, JsxNode, TextNode, TypeNode } from './code.ts'
16
- export type { ContentNode } from './content.ts'
17
- export type { ExportNode, FileNode, ImportNode, SourceNode, UserFileNode } from './file.ts'
18
- export type {
19
- FunctionParamKind,
20
- FunctionParameterNode,
21
- FunctionParametersNode,
22
- FunctionParamNode,
23
- IndexedAccessTypeNode,
24
- ObjectBindingPatternNode,
25
- TypeExpression,
26
- TypeLiteralNode,
27
- } from './function.ts'
28
- export type { InputMeta, InputNode } from './input.ts'
29
- export type { GenericOperationNode, HttpMethod, HttpOperationNode, OperationNode } from './operation.ts'
30
- export type { OutputNode } from './output.ts'
31
- export type { ParameterLocation, ParameterNode } from './parameter.ts'
32
- export type { PropertyNode } from './property.ts'
33
- export type { RequestBodyNode } from './requestBody.ts'
34
- export type { ResponseNode, StatusCode } from './response.ts'
35
- export type {
36
- ArraySchemaNode,
37
- DateSchemaNode,
38
- DatetimeSchemaNode,
39
- EnumSchemaNode,
40
- IntersectionSchemaNode,
41
- NumberSchemaNode,
42
- ObjectSchemaNode,
43
- PrimitiveSchemaType,
44
- RefSchemaNode,
45
- ScalarSchemaNode,
46
- ScalarSchemaType,
47
- SchemaNode,
48
- SchemaNodeByType,
49
- SchemaType,
50
- StringSchemaNode,
51
- TimeSchemaNode,
52
- UnionSchemaNode,
53
- UrlSchemaNode,
54
- } from './schema.ts'
55
-
56
- /**
57
- * Union of all AST node types.
58
- *
59
- * This lets TypeScript narrow types in `switch (node.kind)` blocks.
60
- *
61
- * @example
62
- * ```ts
63
- * function getKind(node: Node): string {
64
- * switch (node.kind) {
65
- * case 'Input':
66
- * return 'input'
67
- * case 'Output':
68
- * return 'output'
69
- * default:
70
- * return 'other'
71
- * }
72
- * }
73
- * ```
74
- */
75
- export type Node =
76
- | InputNode
77
- | OutputNode
78
- | OperationNode
79
- | SchemaNode
80
- | PropertyNode
81
- | ParameterNode
82
- | ResponseNode
83
- | RequestBodyNode
84
- | ContentNode
85
- | FunctionParamNode
86
- | FileNode
87
- | ImportNode
88
- | ExportNode
89
- | SourceNode
90
- | ConstNode
91
- | TypeNode
92
- | FunctionNode
93
- | ArrowFunctionNode
@@ -1,144 +0,0 @@
1
- import type { Streamable } from '@internals/utils'
2
- import { defineNode } from '../defineNode.ts'
3
- import type { BaseNode } from './base.ts'
4
- import type { OperationNode } from './operation.ts'
5
- import type { SchemaNode } from './schema.ts'
6
-
7
- /**
8
- * Metadata for an API document, populated by the adapter and available to every generator.
9
- *
10
- * All fields are plain JSON-serializable values, no `Set`, no `Map`, no class instances.
11
- * Computed fields (`circularNames`, `enumNames`) are pre-calculated once during the adapter
12
- * pre-scan so generators never need to iterate the full schema list themselves.
13
- *
14
- * @example
15
- * ```ts
16
- * const meta: InputMeta = { title: 'Pet Store', version: '1.0.0', baseURL: 'https://petstore.swagger.io/v2', circularNames: [], enumNames: [] }
17
- * ```
18
- */
19
- export type InputMeta = {
20
- /**
21
- * API title from `info.title` in the source document.
22
- */
23
- title?: string
24
- /**
25
- * API description from `info.description` in the source document.
26
- */
27
- description?: string
28
- /**
29
- * API version string from `info.version` in the source document.
30
- */
31
- version?: string
32
- /**
33
- * Resolved base URL from the first matching server entry in the source document.
34
- */
35
- baseURL?: string | null
36
- /**
37
- * Names of schemas that participate in a circular reference chain.
38
- * Computed once during the adapter pre-scan, so a generator never has to
39
- * call `findCircularSchemas` itself.
40
- *
41
- * Convert to a `Set` once at the start of a generator, not per-schema,
42
- * so lookups stay O(1) without repeated allocations.
43
- *
44
- * @example Wrap a circular schema in z.lazy()
45
- * ```ts
46
- * const circular = new Set(meta.circularNames)
47
- * if (circular.has(schema.name)) { ... }
48
- * ```
49
- */
50
- circularNames: ReadonlyArray<string>
51
- /**
52
- * Names of schemas whose type is `enum`.
53
- * Computed once during the adapter pre-scan, so a generator never has to
54
- * filter the schema list itself.
55
- *
56
- * Convert to a `Set` once at the start of a generator when you need repeated
57
- * membership checks, so each check stays O(1) instead of an array scan.
58
- *
59
- * @example Check if a referenced schema is an enum
60
- * `const enums = new Set(meta.enumNames)`
61
- * `const isEnum = enums.has(schemaName)`
62
- */
63
- enumNames: ReadonlyArray<string>
64
- }
65
-
66
- /**
67
- * Input AST node that contains all schemas and operations for one API document.
68
- * Produced by the adapter and consumed by all Kubb plugins.
69
- *
70
- * `Stream` switches `schemas` and `operations` between eager `Array`s (the default) and lazy
71
- * `AsyncIterable`s. The streaming variant `InputNode<true>` yields nodes one at a time.
72
- *
73
- * @example
74
- * ```ts
75
- * const input: InputNode = {
76
- * kind: 'Input',
77
- * schemas: [],
78
- * operations: [],
79
- * meta: { circularNames: [], enumNames: [] },
80
- * }
81
- * ```
82
- *
83
- * @example Streaming variant for large specs
84
- * ```ts
85
- * for await (const schema of inputNode.schemas) {
86
- * // only this one SchemaNode is live here. Previous ones are GC-eligible
87
- * }
88
- * ```
89
- */
90
- export type InputNode<Stream extends boolean = false> = BaseNode & {
91
- /**
92
- * Node kind.
93
- */
94
- kind: 'Input'
95
- /**
96
- * All schema nodes in the document.
97
- */
98
- schemas: Streamable<SchemaNode, Stream>
99
- /**
100
- * All operation nodes in the document.
101
- */
102
- operations: Streamable<OperationNode, Stream>
103
- /**
104
- * Document metadata populated by the adapter.
105
- */
106
- meta: InputMeta
107
- }
108
-
109
- /**
110
- * Definition for the {@link InputNode}.
111
- */
112
- export const inputDef = defineNode<InputNode, Partial<Omit<InputNode, 'kind'>>>({
113
- kind: 'Input',
114
- defaults: { schemas: [], operations: [], meta: { circularNames: [], enumNames: [] } },
115
- children: ['schemas', 'operations'],
116
- visitorKey: 'input',
117
- })
118
-
119
- /**
120
- * Creates an `InputNode`. Pass `stream: true` for the streaming variant whose `schemas` and
121
- * `operations` are `AsyncIterable` sources. Otherwise it builds the eager variant with array
122
- * `schemas`/`operations`. Both variants get the defaulted `meta`.
123
- *
124
- * @example Eager
125
- * ```ts
126
- * const input = createInput()
127
- * // { kind: 'Input', schemas: [], operations: [] }
128
- * ```
129
- *
130
- * @example Streaming
131
- * ```ts
132
- * const node = createInput({ stream: true, schemas: schemasIterable, operations: operationsIterable, meta: { title: 'My API' } })
133
- * ```
134
- */
135
- export function createInput<Stream extends boolean = false>(options: Partial<Omit<InputNode<Stream>, 'kind'>> & { stream?: Stream } = {}): InputNode<Stream> {
136
- const { stream, ...overrides } = options
137
- // Streaming inputs carry AsyncIterable sources, so skip the array defaults that
138
- // inputDef.create applies for the eager variant. Keep the meta default.
139
- if (stream) {
140
- return { kind: 'Input', meta: { circularNames: [], enumNames: [] }, ...overrides } as InputNode<Stream>
141
- }
142
-
143
- return inputDef.create(overrides as Partial<Omit<InputNode, 'kind'>>) as InputNode<Stream>
144
- }
@@ -1,168 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import type { BaseNode } from './base.ts'
3
- import type { ParameterNode } from './parameter.ts'
4
- import { createRequestBody, type RequestBodyNode } from './requestBody.ts'
5
- import type { ResponseNode } from './response.ts'
6
-
7
- /**
8
- * HTTP method an operation responds to.
9
- */
10
- export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE'
11
-
12
- /**
13
- * Transport an operation belongs to.
14
- */
15
- type OperationProtocol = 'http'
16
-
17
- /**
18
- * Fields shared by every operation, regardless of transport.
19
- */
20
- type OperationNodeBase = BaseNode & {
21
- /**
22
- * Node kind.
23
- */
24
- kind: 'Operation'
25
- /**
26
- * Operation identifier, usually from OpenAPI `operationId`.
27
- */
28
- operationId: string
29
- /**
30
- * Group labels for the operation.
31
- * Usually copied from OpenAPI `tags`.
32
- */
33
- tags: Array<string>
34
- /**
35
- * Short one-line operation summary.
36
- */
37
- summary?: string
38
- /**
39
- * Full operation description.
40
- */
41
- description?: string
42
- /**
43
- * Marks the operation as deprecated.
44
- */
45
- deprecated?: boolean
46
- /**
47
- * Query, path, header, and cookie parameters for the operation.
48
- */
49
- parameters: Array<ParameterNode>
50
- /**
51
- * Request body for the operation.
52
- */
53
- requestBody?: RequestBodyNode
54
- /**
55
- * Operation responses.
56
- */
57
- responses: Array<ResponseNode>
58
- }
59
-
60
- /**
61
- * Operation served over HTTP/REST (OpenAPI). `method` and `path` are guaranteed.
62
- *
63
- * @example
64
- * ```ts
65
- * const operation: HttpOperationNode = {
66
- * kind: 'Operation',
67
- * operationId: 'listPets',
68
- * protocol: 'http',
69
- * method: 'GET',
70
- * path: '/pets',
71
- * tags: [],
72
- * parameters: [],
73
- * responses: [],
74
- * }
75
- * ```
76
- */
77
- export type HttpOperationNode = OperationNodeBase & {
78
- /**
79
- * Transport the operation belongs to.
80
- */
81
- protocol?: 'http'
82
- /**
83
- * HTTP method like `'GET'`.
84
- */
85
- method: HttpMethod
86
- /**
87
- * OpenAPI-style path string, for example `/pets/{petId}`, with `{param}` notation preserved.
88
- */
89
- path: string
90
- }
91
-
92
- /**
93
- * Operation for a non-HTTP transport. HTTP-only fields are forbidden.
94
- */
95
- export type GenericOperationNode = OperationNodeBase & {
96
- /**
97
- * Transport the operation belongs to.
98
- */
99
- protocol?: Exclude<OperationProtocol, 'http'>
100
- method?: never
101
- path?: never
102
- }
103
-
104
- /**
105
- * AST node representing one API operation.
106
- *
107
- * Discriminated on `protocol`: an {@link HttpOperationNode} (`protocol: 'http'`) guarantees
108
- * `method` and `path`, while a {@link GenericOperationNode} omits them. Narrow with
109
- * `isHttpOperationNode(node)` or `node.protocol === 'http'` before reading `method`/`path`.
110
- */
111
- export type OperationNode = HttpOperationNode | GenericOperationNode
112
-
113
- type OperationInput = {
114
- operationId: string
115
- method?: HttpOperationNode['method']
116
- path?: HttpOperationNode['path']
117
- requestBody?: Omit<RequestBodyNode, 'kind'>
118
- [key: string]: unknown
119
- }
120
-
121
- /**
122
- * Definition for the {@link OperationNode}. HTTP operations (those carrying both
123
- * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is
124
- * normalized into a `RequestBodyNode`.
125
- */
126
- export const operationDef = defineNode<OperationNode, OperationInput>({
127
- kind: 'Operation',
128
- build: (props) => {
129
- const { requestBody, ...rest } = props
130
- const isHttp = rest.method !== undefined && rest.path !== undefined
131
-
132
- return {
133
- tags: [],
134
- parameters: [],
135
- responses: [],
136
- ...rest,
137
- ...(isHttp ? { protocol: 'http' as const } : {}),
138
- requestBody: requestBody ? createRequestBody(requestBody) : undefined,
139
- }
140
- },
141
- children: ['parameters', 'requestBody', 'responses'],
142
- visitorKey: 'operation',
143
- })
144
-
145
- /**
146
- * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.
147
- *
148
- * @example
149
- * ```ts
150
- * const operation = createOperation({ operationId: 'getPetById', method: 'GET', path: '/pet/{petId}' })
151
- * // tags, parameters, and responses are []
152
- * ```
153
- */
154
- export function createOperation(
155
- props: Pick<HttpOperationNode, 'operationId' | 'method' | 'path'> &
156
- Partial<Omit<HttpOperationNode, 'kind' | 'operationId' | 'method' | 'path' | 'requestBody'>> & {
157
- requestBody?: Omit<RequestBodyNode, 'kind'>
158
- },
159
- ): HttpOperationNode
160
- export function createOperation(
161
- props: Pick<GenericOperationNode, 'operationId'> &
162
- Partial<Omit<GenericOperationNode, 'kind' | 'operationId' | 'requestBody'>> & {
163
- requestBody?: Omit<RequestBodyNode, 'kind'>
164
- },
165
- ): GenericOperationNode
166
- export function createOperation(props: OperationInput): OperationNode {
167
- return operationDef.create(props)
168
- }
@@ -1,49 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import type { BaseNode } from './base.ts'
3
- import type { FileNode } from './file.ts'
4
-
5
- /**
6
- * Output AST node that groups all generated file output for one API document.
7
- *
8
- * Produced by generators and consumed by the build pipeline to write files.
9
- *
10
- * @example
11
- * ```ts
12
- * const output: OutputNode = {
13
- * kind: 'Output',
14
- * files: [],
15
- * }
16
- * ```
17
- */
18
- export type OutputNode = BaseNode & {
19
- /**
20
- * Node kind.
21
- */
22
- kind: 'Output'
23
- /**
24
- * Generated file nodes.
25
- */
26
- files: Array<FileNode>
27
- }
28
-
29
- /**
30
- * Definition for the {@link OutputNode}.
31
- */
32
- export const outputDef = defineNode<OutputNode, Partial<Omit<OutputNode, 'kind'>>>({
33
- kind: 'Output',
34
- defaults: { files: [] },
35
- visitorKey: 'output',
36
- })
37
-
38
- /**
39
- * Creates an `OutputNode` with a stable default for `files`.
40
- *
41
- * @example
42
- * ```ts
43
- * const output = createOutput()
44
- * // { kind: 'Output', files: [] }
45
- * ```
46
- */
47
- export function createOutput(overrides: Partial<Omit<OutputNode, 'kind'>> = {}): OutputNode {
48
- return outputDef.create(overrides)
49
- }
@@ -1,71 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import { optionality } from '../optionality.ts'
3
- import type { BaseNode } from './base.ts'
4
- import type { SchemaNode } from './schema.ts'
5
-
6
- export type ParameterLocation = 'path' | 'query' | 'header' | 'cookie'
7
-
8
- /**
9
- * AST node representing one operation parameter.
10
- *
11
- * @example
12
- * ```ts
13
- * const param: ParameterNode = {
14
- * kind: 'Parameter',
15
- * name: 'petId',
16
- * in: 'path',
17
- * schema: createSchema({ type: 'string' }),
18
- * required: true,
19
- * }
20
- * ```
21
- */
22
- export type ParameterNode = BaseNode & {
23
- kind: 'Parameter'
24
- /**
25
- * Parameter name.
26
- */
27
- name: string
28
- /**
29
- * Parameter location (`path`, `query`, `header`, or `cookie`).
30
- */
31
- in: ParameterLocation
32
- /**
33
- * Parameter schema.
34
- */
35
- schema: SchemaNode
36
- /**
37
- * Whether the parameter is required.
38
- */
39
- required: boolean
40
- }
41
-
42
- type UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>
43
-
44
- /**
45
- * Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's
46
- * `optional`/`nullish` flags are derived from it through {@link optionality}.
47
- */
48
- export const parameterDef = defineNode<ParameterNode, UserParameterNode>({
49
- kind: 'Parameter',
50
- build: (props) => {
51
- const required = props.required ?? false
52
- return { ...props, required, schema: optionality(props.schema, required) }
53
- },
54
- children: ['schema'],
55
- visitorKey: 'parameter',
56
- })
57
-
58
- /**
59
- * Creates a `ParameterNode`.
60
- *
61
- * @example
62
- * ```ts
63
- * const param = createParameter({
64
- * name: 'petId',
65
- * in: 'path',
66
- * required: true,
67
- * schema: createSchema({ type: 'string' }),
68
- * })
69
- * ```
70
- */
71
- export const createParameter = parameterDef.create
@@ -1,67 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import { optionality } from '../optionality.ts'
3
- import type { BaseNode } from './base.ts'
4
- import type { SchemaNode } from './schema.ts'
5
-
6
- /**
7
- * AST node representing one named object property.
8
- *
9
- * @example
10
- * ```ts
11
- * const property: PropertyNode = {
12
- * kind: 'Property',
13
- * name: 'id',
14
- * schema: createSchema({ type: 'integer' }),
15
- * required: true,
16
- * }
17
- * ```
18
- */
19
- export type PropertyNode = BaseNode & {
20
- kind: 'Property'
21
- /**
22
- * Property key.
23
- */
24
- name: string
25
- /**
26
- * Property schema.
27
- */
28
- schema: SchemaNode
29
- /**
30
- * Whether the property is required.
31
- */
32
- required: boolean
33
- }
34
-
35
- /**
36
- * Loosely-typed property accepted by `createProperty`, with `required` optional.
37
- */
38
- export type UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>
39
-
40
- /**
41
- * Definition for the {@link PropertyNode}. `required` defaults to `false`, and the schema's
42
- * `optional`/`nullish` flags are derived from it through {@link optionality}.
43
- */
44
- export const propertyDef = defineNode<PropertyNode, UserPropertyNode>({
45
- kind: 'Property',
46
- build: (props) => {
47
- const required = props.required ?? false
48
- return { ...props, required, schema: optionality(props.schema, required) }
49
- },
50
- children: ['schema'],
51
- visitorKey: 'property',
52
- })
53
-
54
- /**
55
- * Creates a `PropertyNode`.
56
- *
57
- * @example
58
- * ```ts
59
- * const property = createProperty({
60
- * name: 'status',
61
- * required: true,
62
- * schema: createSchema({ type: 'string', nullable: true }),
63
- * })
64
- * // required=true, no optional/nullish
65
- * ```
66
- */
67
- export const createProperty = propertyDef.create
@@ -1,54 +0,0 @@
1
- import { defineNode } from '../defineNode.ts'
2
- import type { BaseNode } from './base.ts'
3
- import type { ContentNode } from './content.ts'
4
-
5
- /**
6
- * AST node representing an operation request body.
7
- *
8
- * Body schemas live exclusively inside the `content` array (one entry per content type),
9
- * mirroring {@link ResponseNode}.
10
- *
11
- * @example
12
- * ```ts
13
- * const requestBody: RequestBodyNode = {
14
- * kind: 'RequestBody',
15
- * required: true,
16
- * content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
17
- * }
18
- * ```
19
- */
20
- export type RequestBodyNode = BaseNode & {
21
- kind: 'RequestBody'
22
- /**
23
- * Request body description carried over from the spec.
24
- */
25
- description?: string
26
- /**
27
- * Whether the request body is required (`requestBody.required: true` in the spec).
28
- * When `false` or absent, the generated `data` parameter should be optional.
29
- */
30
- required?: boolean
31
- /**
32
- * Content type entries for this request body.
33
- *
34
- * When the adapter `contentType` option is set, this array contains exactly one entry for
35
- * that content type. Otherwise it contains one entry per content type declared in the spec,
36
- * so plugins can generate code for every variant (for example, separate hooks for
37
- * `application/json` and `multipart/form-data`).
38
- */
39
- content?: Array<ContentNode>
40
- }
41
-
42
- /**
43
- * Definition for the {@link RequestBodyNode}. Content entries are built upfront with
44
- * {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes.
45
- */
46
- export const requestBodyDef = defineNode<RequestBodyNode>({
47
- kind: 'RequestBody',
48
- children: ['content'],
49
- })
50
-
51
- /**
52
- * Creates a `RequestBodyNode`.
53
- */
54
- export const createRequestBody = requestBodyDef.create