@kubb/ast 5.0.0-beta.5 → 5.0.0-beta.51
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/LICENSE +17 -10
- package/README.md +28 -19
- package/dist/index.cjs +878 -788
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +33 -3326
- package/dist/index.js +863 -750
- package/dist/index.js.map +1 -1
- package/dist/types-BaaNZbSi.d.ts +3581 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.js +1 -0
- package/dist/utils-BIcKgbbc.js +626 -0
- package/dist/utils-BIcKgbbc.js.map +1 -0
- package/dist/utils-CMRZrT-w.cjs +794 -0
- package/dist/utils-CMRZrT-w.cjs.map +1 -0
- package/dist/utils.cjs +18 -0
- package/dist/utils.d.ts +205 -0
- package/dist/utils.js +2 -0
- package/package.json +13 -5
- package/src/constants.ts +10 -49
- package/src/dedupe.ts +200 -0
- package/src/dialect.ts +58 -0
- package/src/dispatch.ts +53 -0
- package/src/factory.ts +154 -21
- package/src/guards.ts +18 -48
- package/src/index.ts +11 -8
- package/src/infer.ts +16 -14
- package/src/nodes/base.ts +2 -0
- package/src/nodes/code.ts +22 -28
- package/src/nodes/content.ts +37 -0
- package/src/nodes/file.ts +17 -15
- package/src/nodes/function.ts +11 -11
- package/src/nodes/http.ts +1 -35
- package/src/nodes/index.ts +10 -12
- package/src/nodes/operation.ts +98 -62
- package/src/nodes/response.ts +21 -14
- package/src/nodes/root.ts +72 -10
- package/src/nodes/schema.ts +18 -15
- package/src/printer.ts +44 -38
- package/src/resolvers.ts +5 -19
- package/src/signature.ts +232 -0
- package/src/transformers.ts +21 -16
- package/src/types.ts +8 -18
- package/src/{utils.ts → utils/ast.ts} +125 -84
- package/src/utils/index.ts +295 -0
- package/src/visitor.ts +239 -281
- package/src/refs.ts +0 -67
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/src/nodes/code.ts
CHANGED
|
@@ -36,21 +36,21 @@ export type ConstNode = BaseNode & {
|
|
|
36
36
|
* Whether the declaration should be exported.
|
|
37
37
|
* @default false
|
|
38
38
|
*/
|
|
39
|
-
export?: boolean
|
|
39
|
+
export?: boolean | null
|
|
40
40
|
/**
|
|
41
41
|
* Optional explicit type annotation.
|
|
42
42
|
* @example 'Pet'
|
|
43
43
|
*/
|
|
44
|
-
type?: string
|
|
44
|
+
type?: string | null
|
|
45
45
|
/**
|
|
46
46
|
* JSDoc documentation metadata.
|
|
47
47
|
*/
|
|
48
|
-
JSDoc?: JSDocNode
|
|
48
|
+
JSDoc?: JSDocNode | null
|
|
49
49
|
/**
|
|
50
50
|
* Whether to append `as const` to the declaration.
|
|
51
51
|
* @default false
|
|
52
52
|
*/
|
|
53
|
-
asConst?: boolean
|
|
53
|
+
asConst?: boolean | null
|
|
54
54
|
/**
|
|
55
55
|
* Child nodes representing the value of the constant (children of the `Const` component).
|
|
56
56
|
* Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
|
|
@@ -83,11 +83,11 @@ export type TypeNode = BaseNode & {
|
|
|
83
83
|
* Whether the declaration should be exported.
|
|
84
84
|
* @default false
|
|
85
85
|
*/
|
|
86
|
-
export?: boolean
|
|
86
|
+
export?: boolean | null
|
|
87
87
|
/**
|
|
88
88
|
* JSDoc documentation metadata.
|
|
89
89
|
*/
|
|
90
|
-
JSDoc?: JSDocNode
|
|
90
|
+
JSDoc?: JSDocNode | null
|
|
91
91
|
/**
|
|
92
92
|
* Child nodes representing the type body (children of the `Type` component).
|
|
93
93
|
* Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
|
|
@@ -95,12 +95,6 @@ export type TypeNode = BaseNode & {
|
|
|
95
95
|
nodes?: Array<CodeNode>
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
/**
|
|
99
|
-
* Convenience alias for {@link TypeNode}.
|
|
100
|
-
* @deprecated Use `TypeNode` directly.
|
|
101
|
-
*/
|
|
102
|
-
export type TypeDeclarationNode = TypeNode
|
|
103
|
-
|
|
104
98
|
/**
|
|
105
99
|
* AST node representing a TypeScript `function` declaration.
|
|
106
100
|
*
|
|
@@ -126,35 +120,35 @@ export type FunctionNode = BaseNode & {
|
|
|
126
120
|
* Whether the function is a default export.
|
|
127
121
|
* @default false
|
|
128
122
|
*/
|
|
129
|
-
default?: boolean
|
|
123
|
+
default?: boolean | null
|
|
130
124
|
/**
|
|
131
125
|
* Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).
|
|
132
126
|
*/
|
|
133
|
-
params?: string
|
|
127
|
+
params?: string | null
|
|
134
128
|
/**
|
|
135
129
|
* Whether the function should be exported.
|
|
136
130
|
* @default false
|
|
137
131
|
*/
|
|
138
|
-
export?: boolean
|
|
132
|
+
export?: boolean | null
|
|
139
133
|
/**
|
|
140
134
|
* Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
141
135
|
* @default false
|
|
142
136
|
*/
|
|
143
|
-
async?: boolean
|
|
137
|
+
async?: boolean | null
|
|
144
138
|
/**
|
|
145
139
|
* TypeScript generic type parameters.
|
|
146
140
|
* @example ['T', 'U extends string']
|
|
147
141
|
*/
|
|
148
|
-
generics?: string | string
|
|
142
|
+
generics?: string | Array<string> | null
|
|
149
143
|
/**
|
|
150
144
|
* Return type annotation.
|
|
151
145
|
* @example 'Pet'
|
|
152
146
|
*/
|
|
153
|
-
returnType?: string
|
|
147
|
+
returnType?: string | null
|
|
154
148
|
/**
|
|
155
149
|
* JSDoc documentation metadata.
|
|
156
150
|
*/
|
|
157
|
-
JSDoc?: JSDocNode
|
|
151
|
+
JSDoc?: JSDocNode | null
|
|
158
152
|
/**
|
|
159
153
|
* Child nodes representing the function body (children of the `Function` component).
|
|
160
154
|
* Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
|
|
@@ -187,40 +181,40 @@ export type ArrowFunctionNode = BaseNode & {
|
|
|
187
181
|
* Whether the function is a default export.
|
|
188
182
|
* @default false
|
|
189
183
|
*/
|
|
190
|
-
default?: boolean
|
|
184
|
+
default?: boolean | null
|
|
191
185
|
/**
|
|
192
186
|
* Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).
|
|
193
187
|
*/
|
|
194
|
-
params?: string
|
|
188
|
+
params?: string | null
|
|
195
189
|
/**
|
|
196
190
|
* Whether the arrow function should be exported.
|
|
197
191
|
* @default false
|
|
198
192
|
*/
|
|
199
|
-
export?: boolean
|
|
193
|
+
export?: boolean | null
|
|
200
194
|
/**
|
|
201
195
|
* Whether the arrow function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
202
196
|
* @default false
|
|
203
197
|
*/
|
|
204
|
-
async?: boolean
|
|
198
|
+
async?: boolean | null
|
|
205
199
|
/**
|
|
206
200
|
* TypeScript generic type parameters.
|
|
207
201
|
* @example ['T', 'U extends string']
|
|
208
202
|
*/
|
|
209
|
-
generics?: string | string
|
|
203
|
+
generics?: string | Array<string> | null
|
|
210
204
|
/**
|
|
211
205
|
* Return type annotation.
|
|
212
206
|
* @example 'Pet'
|
|
213
207
|
*/
|
|
214
|
-
returnType?: string
|
|
208
|
+
returnType?: string | null
|
|
215
209
|
/**
|
|
216
210
|
* JSDoc documentation metadata.
|
|
217
211
|
*/
|
|
218
|
-
JSDoc?: JSDocNode
|
|
212
|
+
JSDoc?: JSDocNode | null
|
|
219
213
|
/**
|
|
220
214
|
* Render the arrow function body as a single-line expression.
|
|
221
215
|
* @default false
|
|
222
216
|
*/
|
|
223
|
-
singleLine?: boolean
|
|
217
|
+
singleLine?: boolean | null
|
|
224
218
|
/**
|
|
225
219
|
* Child nodes representing the function body (children of the `Function.Arrow` component).
|
|
226
220
|
* Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
|
|
@@ -255,7 +249,7 @@ export type TextNode = BaseNode & {
|
|
|
255
249
|
* AST node representing a line break in the source output.
|
|
256
250
|
*
|
|
257
251
|
* Corresponds to `<br/>` in JSX components. When printed, produces an empty
|
|
258
|
-
* string that
|
|
252
|
+
* string that, joined with `\n` by `printNodes` creates a blank line
|
|
259
253
|
* between surrounding code nodes.
|
|
260
254
|
*
|
|
261
255
|
* @example
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BaseNode } from './base.ts'
|
|
2
|
+
import type { SchemaNode } from './schema.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* AST node representing one content-type entry of a request body or response.
|
|
6
|
+
*
|
|
7
|
+
* One entry per content type declared in the spec (e.g. `application/json`,
|
|
8
|
+
* `multipart/form-data`), each carrying its own body schema.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const content: ContentNode = {
|
|
13
|
+
* kind: 'Content',
|
|
14
|
+
* contentType: 'application/json',
|
|
15
|
+
* schema: createSchema({ type: 'string' }),
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type ContentNode = BaseNode & {
|
|
20
|
+
/**
|
|
21
|
+
* Node kind.
|
|
22
|
+
*/
|
|
23
|
+
kind: 'Content'
|
|
24
|
+
/**
|
|
25
|
+
* The content type for this entry (e.g. `'application/json'`).
|
|
26
|
+
*/
|
|
27
|
+
contentType: string
|
|
28
|
+
/**
|
|
29
|
+
* Body schema for this content type.
|
|
30
|
+
*/
|
|
31
|
+
schema?: SchemaNode
|
|
32
|
+
/**
|
|
33
|
+
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
34
|
+
* Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.
|
|
35
|
+
*/
|
|
36
|
+
keysToOmit?: Array<string> | null
|
|
37
|
+
}
|
package/src/nodes/file.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { CodeNode } from './code.ts'
|
|
|
4
4
|
/**
|
|
5
5
|
* Supported file extensions.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`
|
|
8
8
|
|
|
9
9
|
type ImportName = string | Array<string | { propertyName: string; name?: string }>
|
|
10
10
|
|
|
@@ -50,18 +50,18 @@ export type ImportNode = BaseNode & {
|
|
|
50
50
|
* - `false` generates `import { Type } from './path'`
|
|
51
51
|
* @default false
|
|
52
52
|
*/
|
|
53
|
-
isTypeOnly?: boolean
|
|
53
|
+
isTypeOnly?: boolean | null
|
|
54
54
|
/**
|
|
55
55
|
* Import entire module as namespace.
|
|
56
56
|
* - `true` generates `import * as Name from './path'`
|
|
57
57
|
* - `false` generates standard import
|
|
58
58
|
* @default false
|
|
59
59
|
*/
|
|
60
|
-
isNameSpace?: boolean
|
|
60
|
+
isNameSpace?: boolean | null
|
|
61
61
|
/**
|
|
62
62
|
* When set, the import path is resolved relative to this root.
|
|
63
63
|
*/
|
|
64
|
-
root?: string
|
|
64
|
+
root?: string | null
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
@@ -94,7 +94,7 @@ export type ExportNode = BaseNode & {
|
|
|
94
94
|
* @example ['useState']
|
|
95
95
|
* @example 'React'
|
|
96
96
|
*/
|
|
97
|
-
name?: string | Array<string>
|
|
97
|
+
name?: string | Array<string> | null
|
|
98
98
|
/**
|
|
99
99
|
* Path for the export.
|
|
100
100
|
* @example '@kubb/core'
|
|
@@ -106,14 +106,14 @@ export type ExportNode = BaseNode & {
|
|
|
106
106
|
* - `false` generates `export { Type } from './path'`
|
|
107
107
|
* @default false
|
|
108
108
|
*/
|
|
109
|
-
isTypeOnly?: boolean
|
|
109
|
+
isTypeOnly?: boolean | null
|
|
110
110
|
/**
|
|
111
111
|
* Export as an aliased namespace.
|
|
112
112
|
* - `true` generates `export * as aliasName from './path'`
|
|
113
113
|
* - `false` generates a standard export
|
|
114
114
|
* @default false
|
|
115
115
|
*/
|
|
116
|
-
asAlias?: boolean
|
|
116
|
+
asAlias?: boolean | null
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
/**
|
|
@@ -134,22 +134,22 @@ export type SourceNode = BaseNode & {
|
|
|
134
134
|
/**
|
|
135
135
|
* Optional name identifying this source (used for deduplication and barrel generation).
|
|
136
136
|
*/
|
|
137
|
-
name?: string
|
|
137
|
+
name?: string | null
|
|
138
138
|
/**
|
|
139
139
|
* Mark this source as a type-only export.
|
|
140
140
|
* @default false
|
|
141
141
|
*/
|
|
142
|
-
isTypeOnly?: boolean
|
|
142
|
+
isTypeOnly?: boolean | null
|
|
143
143
|
/**
|
|
144
144
|
* Include `export` keyword in the generated source.
|
|
145
145
|
* @default false
|
|
146
146
|
*/
|
|
147
|
-
isExportable?: boolean
|
|
147
|
+
isExportable?: boolean | null
|
|
148
148
|
/**
|
|
149
149
|
* Include this source in barrel/index file generation.
|
|
150
150
|
* @default false
|
|
151
151
|
*/
|
|
152
|
-
isIndexable?: boolean
|
|
152
|
+
isIndexable?: boolean | null
|
|
153
153
|
/**
|
|
154
154
|
* Structured child nodes representing the content of this source fragment, in DOM order.
|
|
155
155
|
* Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
|
|
@@ -180,8 +180,8 @@ export type SourceNode = BaseNode & {
|
|
|
180
180
|
export type FileNode<TMeta extends object = object> = BaseNode & {
|
|
181
181
|
kind: 'File'
|
|
182
182
|
/**
|
|
183
|
-
* Unique identifier derived from a SHA256 hash of the file path.
|
|
184
|
-
*
|
|
183
|
+
* Unique identifier derived from a SHA256 hash of the file path. Computed
|
|
184
|
+
* by `createFile`; callers do not need to provide it.
|
|
185
185
|
*/
|
|
186
186
|
id: string
|
|
187
187
|
/**
|
|
@@ -221,10 +221,12 @@ export type FileNode<TMeta extends object = object> = BaseNode & {
|
|
|
221
221
|
meta?: TMeta
|
|
222
222
|
/**
|
|
223
223
|
* Optional banner prepended to the generated file content.
|
|
224
|
+
* Accepts `null` so `resolver.resolveBanner()` results can be passed directly.
|
|
224
225
|
*/
|
|
225
|
-
banner?: string
|
|
226
|
+
banner?: string | null
|
|
226
227
|
/**
|
|
227
228
|
* Optional footer appended to the generated file content.
|
|
229
|
+
* Accepts `null` so `resolver.resolveFooter()` results can be passed directly.
|
|
228
230
|
*/
|
|
229
|
-
footer?: string
|
|
231
|
+
footer?: string | null
|
|
230
232
|
}
|
package/src/nodes/function.ts
CHANGED
|
@@ -4,9 +4,9 @@ import type { BaseNode } from './base.ts'
|
|
|
4
4
|
* AST node representing a language-agnostic type expression used as a function parameter
|
|
5
5
|
* type annotation. Each language printer renders the variant into its own syntax.
|
|
6
6
|
*
|
|
7
|
-
* - `struct`
|
|
7
|
+
* - `struct` an inline anonymous type grouping named fields.
|
|
8
8
|
* TypeScript renders as `{ petId: string; name?: string }`.
|
|
9
|
-
* - `member`
|
|
9
|
+
* - `member` a single named field accessed from a named group type.
|
|
10
10
|
* TypeScript renders as `PathParams['petId']`.
|
|
11
11
|
*
|
|
12
12
|
* @example Reference variant
|
|
@@ -35,7 +35,7 @@ export type ParamsTypeNode = BaseNode & {
|
|
|
35
35
|
} & (
|
|
36
36
|
| {
|
|
37
37
|
/**
|
|
38
|
-
* Reference variant
|
|
38
|
+
* Reference variant, a plain type name or identifier.
|
|
39
39
|
* TypeScript renders as-is, e.g. `string`, `QueryParams`, `Partial<Config>`.
|
|
40
40
|
*/
|
|
41
41
|
variant: 'reference'
|
|
@@ -46,7 +46,7 @@ export type ParamsTypeNode = BaseNode & {
|
|
|
46
46
|
}
|
|
47
47
|
| {
|
|
48
48
|
/**
|
|
49
|
-
* Struct variant
|
|
49
|
+
* Struct variant, an inline anonymous type grouping named fields.
|
|
50
50
|
* TypeScript renders as `{ key: Type; other?: OtherType }`.
|
|
51
51
|
*/
|
|
52
52
|
variant: 'struct'
|
|
@@ -61,7 +61,7 @@ export type ParamsTypeNode = BaseNode & {
|
|
|
61
61
|
}
|
|
62
62
|
| {
|
|
63
63
|
/**
|
|
64
|
-
* Member variant
|
|
64
|
+
* Member variant, a single named field accessed from a group type.
|
|
65
65
|
* TypeScript renders as `Base['key']`.
|
|
66
66
|
*/
|
|
67
67
|
variant: 'member'
|
|
@@ -122,7 +122,7 @@ export type FunctionParameterNode = BaseNode & {
|
|
|
122
122
|
*/
|
|
123
123
|
rest?: boolean
|
|
124
124
|
} /**
|
|
125
|
-
* Optional parameter
|
|
125
|
+
* Optional parameter, rendered with `?` and may be omitted by the caller.
|
|
126
126
|
* Cannot be combined with `default` because a defaulted parameter is already optional.
|
|
127
127
|
*/ & (
|
|
128
128
|
| { optional: true; default?: never }
|
|
@@ -196,10 +196,10 @@ export type ParameterGroupNode = BaseNode & {
|
|
|
196
196
|
* Nodes are plain immutable data.
|
|
197
197
|
*
|
|
198
198
|
* Renders differently depending on the output mode:
|
|
199
|
-
* - `declaration` → `(id: string, config: Config = {})`
|
|
200
|
-
* - `call` → `(id, { method, url })`
|
|
201
|
-
* - `keys` → `{ id, config }`
|
|
202
|
-
* - `values` → `{ id: id, config: config }`
|
|
199
|
+
* - `declaration` → `(id: string, config: Config = {})` function declaration parameters
|
|
200
|
+
* - `call` → `(id, { method, url })` function call arguments
|
|
201
|
+
* - `keys` → `{ id, config }` key names only (for destructuring)
|
|
202
|
+
* - `values` → `{ id: id, config: config }` key → value pairs
|
|
203
203
|
*/
|
|
204
204
|
export type FunctionParametersNode = BaseNode & {
|
|
205
205
|
/**
|
|
@@ -218,6 +218,6 @@ export type FunctionParametersNode = BaseNode & {
|
|
|
218
218
|
export type FunctionParamNode = FunctionParameterNode | ParameterGroupNode | FunctionParametersNode | ParamsTypeNode
|
|
219
219
|
|
|
220
220
|
/**
|
|
221
|
-
* Handler map keys
|
|
221
|
+
* Handler map keys, one per `FunctionParamNode` kind.
|
|
222
222
|
*/
|
|
223
223
|
export type FunctionNodeType = 'functionParameter' | 'parameterGroup' | 'functionParameters' | 'paramsType'
|
package/src/nodes/http.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* All supported HTTP status code literals as strings, as used in API specs
|
|
3
3
|
* (for example, `"200"` and `"404"`).
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
type HttpStatusCode =
|
|
6
6
|
// 1xx Informational
|
|
7
7
|
| '100'
|
|
8
8
|
| '101'
|
|
@@ -83,37 +83,3 @@ export type HttpStatusCode =
|
|
|
83
83
|
* ```
|
|
84
84
|
*/
|
|
85
85
|
export type StatusCode = HttpStatusCode | 'default'
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Supported media type strings used in request and response bodies.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* const mediaType: MediaType = 'application/json'
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export type MediaType =
|
|
96
|
-
// Application
|
|
97
|
-
| 'application/json'
|
|
98
|
-
| 'application/xml'
|
|
99
|
-
| 'application/x-www-form-urlencoded'
|
|
100
|
-
| 'application/octet-stream'
|
|
101
|
-
| 'application/pdf'
|
|
102
|
-
| 'application/zip'
|
|
103
|
-
| 'application/graphql'
|
|
104
|
-
// Multipart
|
|
105
|
-
| 'multipart/form-data'
|
|
106
|
-
// Text
|
|
107
|
-
| 'text/plain'
|
|
108
|
-
| 'text/html'
|
|
109
|
-
| 'text/csv'
|
|
110
|
-
| 'text/xml'
|
|
111
|
-
// Image
|
|
112
|
-
| 'image/png'
|
|
113
|
-
| 'image/jpeg'
|
|
114
|
-
| 'image/gif'
|
|
115
|
-
| 'image/webp'
|
|
116
|
-
| 'image/svg+xml'
|
|
117
|
-
// Audio / Video
|
|
118
|
-
| 'audio/mpeg'
|
|
119
|
-
| 'video/mp4'
|
package/src/nodes/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ArrowFunctionNode, ConstNode, FunctionNode, TypeNode } from './code.ts'
|
|
2
|
+
import type { ContentNode } from './content.ts'
|
|
2
3
|
import type { ExportNode, FileNode, ImportNode, SourceNode } from './file.ts'
|
|
3
4
|
import type { FunctionParamNode, ParamsTypeNode } from './function.ts'
|
|
4
|
-
import type { OperationNode } from './operation.ts'
|
|
5
|
+
import type { OperationNode, RequestBodyNode } from './operation.ts'
|
|
5
6
|
import type { OutputNode } from './output.ts'
|
|
6
7
|
import type { ParameterNode } from './parameter.ts'
|
|
7
8
|
import type { PropertyNode } from './property.ts'
|
|
@@ -9,28 +10,24 @@ import type { ResponseNode } from './response.ts'
|
|
|
9
10
|
import type { InputNode } from './root.ts'
|
|
10
11
|
import type { SchemaNode } from './schema.ts'
|
|
11
12
|
|
|
12
|
-
export type {
|
|
13
|
-
export type { ArrowFunctionNode, BreakNode, CodeNode, ConstNode, FunctionNode, JSDocNode, JsxNode, TextNode,
|
|
13
|
+
export type { NodeKind } from './base.ts'
|
|
14
|
+
export type { ArrowFunctionNode, BreakNode, CodeNode, ConstNode, FunctionNode, JSDocNode, JsxNode, TextNode, TypeNode } from './code.ts'
|
|
15
|
+
export type { ContentNode } from './content.ts'
|
|
14
16
|
export type { ExportNode, FileNode, ImportNode, SourceNode } from './file.ts'
|
|
15
17
|
export type { FunctionNodeType, FunctionParameterNode, FunctionParametersNode, FunctionParamNode, ParameterGroupNode, ParamsTypeNode } from './function.ts'
|
|
16
|
-
export type {
|
|
17
|
-
export type { HttpMethod, OperationNode } from './operation.ts'
|
|
18
|
+
export type { StatusCode } from './http.ts'
|
|
19
|
+
export type { GenericOperationNode, HttpMethod, HttpOperationNode, OperationNode, RequestBodyNode } from './operation.ts'
|
|
18
20
|
export type { OutputNode } from './output.ts'
|
|
19
21
|
export type { ParameterLocation, ParameterNode } from './parameter.ts'
|
|
20
22
|
export type { PropertyNode } from './property.ts'
|
|
21
23
|
export type { ResponseNode } from './response.ts'
|
|
22
|
-
export type { InputMeta, InputNode } from './root.ts'
|
|
24
|
+
export type { InputMeta, InputNode, InputStreamNode } from './root.ts'
|
|
23
25
|
export type {
|
|
24
26
|
ArraySchemaNode,
|
|
25
|
-
ComplexSchemaType,
|
|
26
27
|
DateSchemaNode,
|
|
27
28
|
DatetimeSchemaNode,
|
|
28
29
|
EnumSchemaNode,
|
|
29
|
-
EnumValueNode,
|
|
30
|
-
FormatStringSchemaNode,
|
|
31
30
|
IntersectionSchemaNode,
|
|
32
|
-
Ipv4SchemaNode,
|
|
33
|
-
Ipv6SchemaNode,
|
|
34
31
|
NumberSchemaNode,
|
|
35
32
|
ObjectSchemaNode,
|
|
36
33
|
PrimitiveSchemaType,
|
|
@@ -40,7 +37,6 @@ export type {
|
|
|
40
37
|
SchemaNode,
|
|
41
38
|
SchemaNodeByType,
|
|
42
39
|
SchemaType,
|
|
43
|
-
SpecialSchemaType,
|
|
44
40
|
StringSchemaNode,
|
|
45
41
|
TimeSchemaNode,
|
|
46
42
|
UnionSchemaNode,
|
|
@@ -74,6 +70,8 @@ export type Node =
|
|
|
74
70
|
| PropertyNode
|
|
75
71
|
| ParameterNode
|
|
76
72
|
| ResponseNode
|
|
73
|
+
| RequestBodyNode
|
|
74
|
+
| ContentNode
|
|
77
75
|
| FunctionParamNode
|
|
78
76
|
| FileNode
|
|
79
77
|
| ImportNode
|
package/src/nodes/operation.ts
CHANGED
|
@@ -1,44 +1,67 @@
|
|
|
1
1
|
import type { BaseNode } from './base.ts'
|
|
2
|
+
import type { ContentNode } from './content.ts'
|
|
2
3
|
import type { ParameterNode } from './parameter.ts'
|
|
3
4
|
import type { ResponseNode } from './response.ts'
|
|
4
|
-
import type { SchemaNode } from './schema.ts'
|
|
5
5
|
|
|
6
6
|
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Transport an operation belongs to.
|
|
10
|
+
*/
|
|
11
|
+
type OperationProtocol = 'http'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* AST node representing an operation request body.
|
|
15
|
+
*
|
|
16
|
+
* Body schemas live exclusively inside the `content` array (one entry per content type),
|
|
17
|
+
* mirroring {@link ResponseNode}.
|
|
10
18
|
*
|
|
11
19
|
* @example
|
|
12
20
|
* ```ts
|
|
13
|
-
* const
|
|
14
|
-
* kind: '
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* path: '/pets',
|
|
18
|
-
* tags: [],
|
|
19
|
-
* parameters: [],
|
|
20
|
-
* responses: [],
|
|
21
|
+
* const requestBody: RequestBodyNode = {
|
|
22
|
+
* kind: 'RequestBody',
|
|
23
|
+
* required: true,
|
|
24
|
+
* content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
|
|
21
25
|
* }
|
|
22
26
|
* ```
|
|
23
27
|
*/
|
|
24
|
-
export type
|
|
28
|
+
export type RequestBodyNode = BaseNode & {
|
|
25
29
|
/**
|
|
26
30
|
* Node kind.
|
|
27
31
|
*/
|
|
28
|
-
kind: '
|
|
32
|
+
kind: 'RequestBody'
|
|
29
33
|
/**
|
|
30
|
-
*
|
|
34
|
+
* Human-readable request body description.
|
|
31
35
|
*/
|
|
32
|
-
|
|
36
|
+
description?: string
|
|
33
37
|
/**
|
|
34
|
-
*
|
|
38
|
+
* Whether the request body is required (`requestBody.required: true` in the spec).
|
|
39
|
+
* When `false` or absent, the generated `data` parameter should be optional.
|
|
35
40
|
*/
|
|
36
|
-
|
|
41
|
+
required?: boolean
|
|
37
42
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
43
|
+
* All available content type entries for this request body.
|
|
44
|
+
*
|
|
45
|
+
* When the adapter `contentType` option is set, this array contains exactly one entry for
|
|
46
|
+
* that content type. Otherwise it contains one entry per content type declared in the spec,
|
|
47
|
+
* so that plugins can generate code for every variant (e.g. separate hooks for
|
|
48
|
+
* `application/json` and `multipart/form-data`).
|
|
40
49
|
*/
|
|
41
|
-
|
|
50
|
+
content?: Array<ContentNode>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Fields shared by every operation, regardless of transport.
|
|
55
|
+
*/
|
|
56
|
+
type OperationNodeBase = BaseNode & {
|
|
57
|
+
/**
|
|
58
|
+
* Node kind.
|
|
59
|
+
*/
|
|
60
|
+
kind: 'Operation'
|
|
61
|
+
/**
|
|
62
|
+
* Operation identifier, usually from OpenAPI `operationId`.
|
|
63
|
+
*/
|
|
64
|
+
operationId: string
|
|
42
65
|
/**
|
|
43
66
|
* Group labels for the operation.
|
|
44
67
|
* Usually copied from OpenAPI `tags`.
|
|
@@ -61,51 +84,64 @@ export type OperationNode = BaseNode & {
|
|
|
61
84
|
*/
|
|
62
85
|
parameters: Array<ParameterNode>
|
|
63
86
|
/**
|
|
64
|
-
* Request body
|
|
65
|
-
*/
|
|
66
|
-
requestBody?:
|
|
67
|
-
/**
|
|
68
|
-
* Human-readable request body description.
|
|
69
|
-
*/
|
|
70
|
-
description?: string
|
|
71
|
-
/**
|
|
72
|
-
* Whether the request body is required (`requestBody.required: true` in the spec).
|
|
73
|
-
* When `false` or absent, the generated `data` parameter should be optional.
|
|
74
|
-
*/
|
|
75
|
-
required?: boolean
|
|
76
|
-
/**
|
|
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
|
-
* ```
|
|
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
|
-
}>
|
|
106
|
-
}
|
|
87
|
+
* Request body for the operation.
|
|
88
|
+
*/
|
|
89
|
+
requestBody?: RequestBodyNode
|
|
107
90
|
/**
|
|
108
91
|
* Operation responses.
|
|
109
92
|
*/
|
|
110
93
|
responses: Array<ResponseNode>
|
|
111
94
|
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Operation served over HTTP/REST (OpenAPI). `method` and `path` are guaranteed.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* const operation: HttpOperationNode = {
|
|
102
|
+
* kind: 'Operation',
|
|
103
|
+
* operationId: 'listPets',
|
|
104
|
+
* protocol: 'http',
|
|
105
|
+
* method: 'GET',
|
|
106
|
+
* path: '/pets',
|
|
107
|
+
* tags: [],
|
|
108
|
+
* parameters: [],
|
|
109
|
+
* responses: [],
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export type HttpOperationNode = OperationNodeBase & {
|
|
114
|
+
/**
|
|
115
|
+
* Transport the operation belongs to.
|
|
116
|
+
*/
|
|
117
|
+
protocol?: 'http'
|
|
118
|
+
/**
|
|
119
|
+
* HTTP method like `'GET'`.
|
|
120
|
+
*/
|
|
121
|
+
method: HttpMethod
|
|
122
|
+
/**
|
|
123
|
+
* OpenAPI-style path string, for example `/pets/{petId}`, with `{param}` notation preserved.
|
|
124
|
+
*/
|
|
125
|
+
path: string
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Operation for a non-HTTP transport. HTTP-only fields are forbidden.
|
|
130
|
+
*/
|
|
131
|
+
export type GenericOperationNode = OperationNodeBase & {
|
|
132
|
+
/**
|
|
133
|
+
* Transport the operation belongs to.
|
|
134
|
+
*/
|
|
135
|
+
protocol?: Exclude<OperationProtocol, 'http'>
|
|
136
|
+
method?: never
|
|
137
|
+
path?: never
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* AST node representing one API operation.
|
|
142
|
+
*
|
|
143
|
+
* Discriminated on `protocol`: an {@link HttpOperationNode} (`protocol: 'http'`) guarantees
|
|
144
|
+
* `method` and `path`, while a {@link GenericOperationNode} omits them. Narrow with
|
|
145
|
+
* `isHttpOperationNode(node)` or `node.protocol === 'http'` before reading `method`/`path`.
|
|
146
|
+
*/
|
|
147
|
+
export type OperationNode = HttpOperationNode | GenericOperationNode
|