@kubb/ast 5.0.0-alpha.16 → 5.0.0-alpha.17

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/src/infer.ts ADDED
@@ -0,0 +1,130 @@
1
+ import type {
2
+ ArraySchemaNode,
3
+ DateSchemaNode,
4
+ DatetimeSchemaNode,
5
+ EnumSchemaNode,
6
+ IntersectionSchemaNode,
7
+ NumberSchemaNode,
8
+ ObjectSchemaNode,
9
+ RefSchemaNode,
10
+ ScalarSchemaNode,
11
+ SchemaNode,
12
+ StringSchemaNode,
13
+ TimeSchemaNode,
14
+ UnionSchemaNode,
15
+ UrlSchemaNode,
16
+ } from './nodes/index.ts'
17
+
18
+ /**
19
+ * Shared parser options used by OAS-to-AST inference and parser flows.
20
+ */
21
+ export type ParserOptions = {
22
+ /**
23
+ * How `format: 'date-time'` schemas are represented. `false` falls through to a plain string.
24
+ */
25
+ dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date'
26
+ /**
27
+ * Whether `type: 'integer'` and `format: 'int64'` produce `number` or `bigint` nodes.
28
+ */
29
+ integerType?: 'number' | 'bigint'
30
+ /**
31
+ * AST type used when no schema type can be inferred.
32
+ */
33
+ unknownType: 'any' | 'unknown' | 'void'
34
+ /**
35
+ * AST type used for completely empty schemas (`{}`).
36
+ */
37
+ emptySchemaType: 'any' | 'unknown' | 'void'
38
+ /**
39
+ * Suffix appended to derived enum names when building property schema names.
40
+ */
41
+ enumSuffix: 'enum' | (string & {})
42
+ }
43
+
44
+ /**
45
+ * Maps each `dateType` option value to the AST node produced by `format: 'date-time'`.
46
+ */
47
+ type DateTimeNodeByDateType = {
48
+ date: DateSchemaNode
49
+ string: DatetimeSchemaNode
50
+ stringOffset: DatetimeSchemaNode
51
+ stringLocal: DatetimeSchemaNode
52
+ false: StringSchemaNode
53
+ }
54
+
55
+ /**
56
+ * Resolves the AST node produced by `format: 'date-time'` based on the `dateType` option.
57
+ */
58
+ type ResolveDateTimeNode<TDateType extends ParserOptions['dateType']> = DateTimeNodeByDateType[TDateType extends keyof DateTimeNodeByDateType
59
+ ? TDateType
60
+ : 'string']
61
+
62
+ /**
63
+ * Ordered list of `[schema-shape, SchemaNode]` pairs.
64
+ * `InferSchemaNode` walks this tuple in order and returns the first matching node type.
65
+ */
66
+ type SchemaNodeMap<TDateType extends ParserOptions['dateType'] = 'string'> = [
67
+ [{ $ref: string }, RefSchemaNode],
68
+ [{ allOf: ReadonlyArray<unknown>; properties: object }, IntersectionSchemaNode],
69
+ [{ allOf: readonly [unknown, unknown, ...unknown[]] }, IntersectionSchemaNode],
70
+ [{ allOf: ReadonlyArray<unknown> }, SchemaNode],
71
+ [{ oneOf: ReadonlyArray<unknown> }, UnionSchemaNode],
72
+ [{ anyOf: ReadonlyArray<unknown> }, UnionSchemaNode],
73
+ [{ const: null }, ScalarSchemaNode],
74
+ [{ const: string | number | boolean }, EnumSchemaNode],
75
+ [{ type: ReadonlyArray<string> }, UnionSchemaNode],
76
+ [{ type: 'array'; enum: ReadonlyArray<unknown> }, ArraySchemaNode],
77
+ [{ enum: ReadonlyArray<unknown> }, EnumSchemaNode],
78
+ [{ type: 'enum' }, EnumSchemaNode],
79
+ [{ type: 'union' }, UnionSchemaNode],
80
+ [{ type: 'intersection' }, IntersectionSchemaNode],
81
+ [{ type: 'tuple' }, ArraySchemaNode],
82
+ [{ type: 'ref' }, RefSchemaNode],
83
+ [{ type: 'datetime' }, DatetimeSchemaNode],
84
+ [{ type: 'date' }, DateSchemaNode],
85
+ [{ type: 'time' }, TimeSchemaNode],
86
+ [{ type: 'url' }, UrlSchemaNode],
87
+ [{ type: 'object' }, ObjectSchemaNode],
88
+ [{ additionalProperties: boolean | {} }, ObjectSchemaNode],
89
+ [{ type: 'array' }, ArraySchemaNode],
90
+ [{ items: object }, ArraySchemaNode],
91
+ [{ prefixItems: ReadonlyArray<unknown> }, ArraySchemaNode],
92
+ [{ type: string; format: 'date-time' }, ResolveDateTimeNode<TDateType>],
93
+ [{ type: string; format: 'date' }, DateSchemaNode],
94
+ [{ type: string; format: 'time' }, TimeSchemaNode],
95
+ [{ format: 'date-time' }, ResolveDateTimeNode<TDateType>],
96
+ [{ format: 'date' }, DateSchemaNode],
97
+ [{ format: 'time' }, TimeSchemaNode],
98
+ [{ type: 'string' }, StringSchemaNode],
99
+ [{ type: 'number' }, NumberSchemaNode],
100
+ [{ type: 'integer' }, NumberSchemaNode],
101
+ [{ type: 'bigint' }, NumberSchemaNode],
102
+ [{ type: string }, ScalarSchemaNode],
103
+ [{ minLength: number }, StringSchemaNode],
104
+ [{ maxLength: number }, StringSchemaNode],
105
+ [{ pattern: string }, StringSchemaNode],
106
+ [{ minimum: number }, NumberSchemaNode],
107
+ [{ maximum: number }, NumberSchemaNode],
108
+ ]
109
+
110
+ /**
111
+ * Infers the matching AST `SchemaNode` type from an input schema shape.
112
+ */
113
+ export type InferSchemaNode<
114
+ TSchema extends object,
115
+ TDateType extends ParserOptions['dateType'] = 'string',
116
+ TEntries extends ReadonlyArray<[object, SchemaNode]> = SchemaNodeMap<TDateType>,
117
+ > = TEntries extends [infer TEntry extends [object, SchemaNode], ...infer TRest extends ReadonlyArray<[object, SchemaNode]>]
118
+ ? TSchema extends TEntry[0]
119
+ ? TEntry[1]
120
+ : InferSchemaNode<TSchema, TDateType, TRest>
121
+ : SchemaNode
122
+
123
+ /**
124
+ * Backward-compatible alias for `InferSchemaNode`.
125
+ */
126
+ export type InferSchema<
127
+ TSchema extends object,
128
+ TDateType extends ParserOptions['dateType'] = 'string',
129
+ TEntries extends ReadonlyArray<[object, SchemaNode]> = SchemaNodeMap<TDateType>,
130
+ > = InferSchemaNode<TSchema, TDateType, TEntries>
package/src/mocks.ts CHANGED
@@ -2,7 +2,7 @@ import { createOperation, createParameter, createProperty, createResponse, creat
2
2
  import type { RootNode } from './nodes/root.ts'
3
3
 
4
4
  /**
5
- * Minimal single-resource tree: one `Pet` schema and one `getPetById` operation.
5
+ * Builds a minimal sample AST with one `Pet` schema and one `getPetById` operation.
6
6
  */
7
7
  export function buildSampleTree(): RootNode {
8
8
  const petSchema = createSchema({
@@ -33,8 +33,9 @@ export function buildSampleTree(): RootNode {
33
33
  }
34
34
 
35
35
  /**
36
- * PetStore-like tree: six named schemas (`Pet`, `NewPet`, `PetList`, `Error`, `PetOrError`, `FullPet`)
37
- * and two operations (`listPets`, `createPet`).
36
+ * Builds a PetStore-like fixture AST with:
37
+ * - six named schemas (`Pet`, `NewPet`, `PetList`, `Error`, `PetOrError`, `FullPet`)
38
+ * - two operations (`listPets`, `createPet`)
38
39
  */
39
40
  export function buildFixture(): RootNode {
40
41
  const refPet = createSchema({ type: 'ref', ref: 'Pet' })
package/src/nodes/base.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  /**
2
- * Kind discriminant for every AST node.
2
+ * `kind` values used by AST nodes.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * const kind: NodeKind = 'Schema'
7
+ * ```
3
8
  */
4
9
  export type NodeKind =
5
10
  | 'Root'
@@ -13,13 +18,26 @@ export type NodeKind =
13
18
  | 'FunctionParameters'
14
19
 
15
20
  /**
16
- * Common base for all AST nodes.
21
+ * Base shape shared by all AST nodes.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const base: BaseNode = { kind: 'Root' }
26
+ * ```
17
27
  */
18
28
  export type BaseNode = {
29
+ /**
30
+ * Node discriminator.
31
+ */
19
32
  kind: NodeKind
20
33
  }
21
34
 
22
35
  /**
23
- * Any AST node.
36
+ * Minimal node type when only `kind` is needed.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * const node: Node = { kind: 'Operation' }
41
+ * ```
24
42
  */
25
43
  export type Node = BaseNode
@@ -1,28 +1,31 @@
1
1
  import type { BaseNode } from './base.ts'
2
2
 
3
3
  /**
4
- * A single named function parameter.
4
+ * AST node for one function parameter.
5
5
  *
6
- * @example Simple required param
6
+ * @example Required parameter
7
7
  * `name: Type`
8
8
  *
9
9
  * @example Optional param
10
10
  * `name?: Type`
11
11
  *
12
- * @example Param with default
12
+ * @example Parameter with default
13
13
  * `name: Type = defaultValue`
14
14
  *
15
- * @example Rest / spread param
15
+ * @example Rest parameter
16
16
  * `...name: Type[]`
17
17
  */
18
18
  export type FunctionParameterNode = BaseNode & {
19
+ /**
20
+ * Node kind.
21
+ */
19
22
  kind: 'FunctionParameter'
20
23
  /**
21
- * The parameter name as it appears in the function signature.
24
+ * Parameter name in the generated signature.
22
25
  */
23
26
  name: string
24
27
  /**
25
- * TypeScript type annotation (raw string, e.g. `"string"`, `"Pet[]"`, `"Partial<Config>"`).
28
+ * TypeScript type text, for example, `"string"` or `"Pet[]"`.
26
29
  * Omit for untyped JavaScript output.
27
30
  */
28
31
  type?: string
@@ -32,13 +35,13 @@ export type FunctionParameterNode = BaseNode & {
32
35
  */
33
36
  rest?: boolean
34
37
  } /**
35
- * Explicitly optional parameter rendered with `?` in the signature.
36
- * Cannot be combined with `default`; a parameter with a default is implicitly optional.
38
+ * Optional parameter, rendered with `?` in declarations.
39
+ * Cannot be combined with `default` because defaulted parameters are already optional.
37
40
  * @example `name?: Type`
38
41
  */ & (
39
42
  | { optional: true; default?: never }
40
43
  /**
41
- * Required parameter, or a parameter with a default value (implicitly optional).
44
+ * Required parameter, or parameter with a default value.
42
45
  * @example Required: `name: Type`
43
46
  * @example With default: `name: Type = default`
44
47
  */
@@ -46,12 +49,12 @@ export type FunctionParameterNode = BaseNode & {
46
49
  )
47
50
 
48
51
  /**
49
- * An object-destructured function parameter group.
52
+ * AST node for object-destructured function parameters.
50
53
  *
51
- * Renders as `{ key1, key2 }: { key1: Type1; key2: Type2 } = {}` in a declaration,
52
- * or as individual top-level params when `inline` is `true`.
54
+ * This node renders as `{ key1, key2 }: { key1: Type1; key2: Type2 } = {}` in declarations,
55
+ * or as individual top-level parameters when `inline` is `true`.
53
56
  *
54
- * Replaces `mode: 'object'` / `mode: 'inlineSpread'` from the legacy `FunctionParams` API.
57
+ * This replaces `mode: 'object'` and `mode: 'inlineSpread'` from the old `FunctionParams` API.
55
58
  *
56
59
  * @example Object destructuring with auto-computed type (declaration)
57
60
  * `{ id, name }: { id: string; name: string } = {}`
@@ -60,6 +63,9 @@ export type FunctionParameterNode = BaseNode & {
60
63
  * `id: string, name: string`
61
64
  */
62
65
  export type ObjectBindingParameterNode = BaseNode & {
66
+ /**
67
+ * Node kind.
68
+ */
63
69
  kind: 'ObjectBindingParameter'
64
70
  /**
65
71
  * The individual parameters that form the destructured object.
@@ -67,12 +73,12 @@ export type ObjectBindingParameterNode = BaseNode & {
67
73
  */
68
74
  properties: Array<FunctionParameterNode>
69
75
  /**
70
- * Explicit TypeScript type annotation for the whole object param.
71
- * When absent the printer auto-computes `{ key1: Type1; key2: Type2 }` from `params`.
76
+ * Optional type text for the full object parameter.
77
+ * When absent, the printer auto-computes `{ key1: Type1; key2: Type2 }` from `properties`.
72
78
  */
73
79
  type?: string
74
80
  /**
75
- * When `true` the `params` are emitted as individual top-level parameters instead of
81
+ * When `true`, `properties` are emitted as individual top-level parameters instead of
76
82
  * being wrapped in a destructuring pattern (`{ key1, key2 }`).
77
83
  *
78
84
  * Equivalent to `mode: 'inlineSpread'` in the legacy `FunctionParams` API.
@@ -80,8 +86,8 @@ export type ObjectBindingParameterNode = BaseNode & {
80
86
  */
81
87
  inline?: boolean
82
88
  /**
83
- * Whether the whole object group is optional.
84
- * When absent the printer auto-computes this: optional if every child param is optional.
89
+ * Whether the full object binding is optional.
90
+ * If omitted, printers infer this from child properties.
85
91
  */
86
92
  optional?: boolean
87
93
  /**
@@ -92,19 +98,25 @@ export type ObjectBindingParameterNode = BaseNode & {
92
98
  }
93
99
 
94
100
  /**
95
- * A complete ordered parameter list for a function.
101
+ * AST node for a complete function parameter list.
96
102
  *
97
- * The printer is responsible for sorting (required → optional → has-default).
98
- * Nodes themselves are treated as plain, immutable data.
103
+ * Printers are responsible for sorting (`required``optional``defaulted`).
104
+ * Nodes are plain immutable data.
99
105
  *
100
106
  * Renders differently depending on the output mode:
101
- * - `declaration` → `(id: string, config: Config = {})` — typed function parameter list
107
+ * - `declaration` → `(id: string, config: Config = {})` — function declaration parameters
102
108
  * - `call` → `(id, { method, url })` — function call arguments
103
109
  * - `keys` → `{ id, config }` — key names only (for destructuring)
104
110
  * - `values` → `{ id: id, config: config }` — key → value pairs
105
111
  */
106
112
  export type FunctionParametersNode = BaseNode & {
113
+ /**
114
+ * Node kind.
115
+ */
107
116
  kind: 'FunctionParameters'
117
+ /**
118
+ * Ordered parameter nodes.
119
+ */
108
120
  params: Array<FunctionParameterNode | ObjectBindingParameterNode>
109
121
  }
110
122
 
package/src/nodes/http.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
- * All IANA-registered HTTP status codes as string literals, matching how
3
- * they appear as keys in API specifications (e.g. `"200"`, `"404"`).
2
+ * All supported HTTP status code literals as strings, as used in API specs
3
+ * (for example, `"200"` and `"404"`).
4
4
  */
5
5
  export type HttpStatusCode =
6
6
  // 1xx Informational
@@ -72,13 +72,25 @@ export type HttpStatusCode =
72
72
  | '511'
73
73
 
74
74
  /**
75
- * A status code as used in an operation response: a specific HTTP status
76
- * code string or `"default"` as a catch-all fallback.
75
+ * Response status code literal used by operations.
76
+ *
77
+ * Includes specific HTTP status code strings and `"default"` for catch-all responses.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * const status: StatusCode = '200'
82
+ * const fallback: StatusCode = 'default'
83
+ * ```
77
84
  */
78
85
  export type StatusCode = HttpStatusCode | 'default'
79
86
 
80
87
  /**
81
- * Common IANA media types used in API request/response bodies.
88
+ * Supported media type strings used in request and response bodies.
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * const mediaType: MediaType = 'application/json'
93
+ * ```
82
94
  */
83
95
  export type MediaType =
84
96
  // Application
@@ -39,10 +39,20 @@ export type {
39
39
  } from './schema.ts'
40
40
 
41
41
  /**
42
- * Discriminated union of every AST node.
42
+ * Union of all AST node types.
43
43
  *
44
- * Using a concrete union (instead of the bare `BaseNode` alias) lets
45
- * TypeScript narrow the type automatically inside `switch (node.kind)`
46
- * blocks, eliminating the need for manual `as TypeName` casts.
44
+ * This lets TypeScript narrow types in `switch (node.kind)` blocks.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * function getKind(node: Node): string {
49
+ * switch (node.kind) {
50
+ * case 'Root':
51
+ * return 'root'
52
+ * default:
53
+ * return 'other'
54
+ * }
55
+ * }
56
+ * ```
47
57
  */
48
58
  export type Node = RootNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | FunctionNode
@@ -6,43 +6,81 @@ import type { SchemaNode } from './schema.ts'
6
6
  export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE'
7
7
 
8
8
  /**
9
- * A spec-agnostic representation of a single API operation.
9
+ * AST node representing one API operation.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * const operation: OperationNode = {
14
+ * kind: 'Operation',
15
+ * operationId: 'listPets',
16
+ * method: 'GET',
17
+ * path: '/pets',
18
+ * tags: [],
19
+ * parameters: [],
20
+ * responses: [],
21
+ * }
22
+ * ```
10
23
  */
11
24
  export type OperationNode = BaseNode & {
25
+ /**
26
+ * Node kind.
27
+ */
12
28
  kind: 'Operation'
13
29
  /**
14
- * Unique operation identifier (maps to `operationId` in OAS).
30
+ * Operation identifier, usually from OpenAPI `operationId`.
15
31
  */
16
32
  operationId: string
33
+ /**
34
+ * HTTP Method like 'GET'
35
+ */
17
36
  method: HttpMethod
18
37
  /**
19
- * Express-style path string, e.g. `/pets/:petId`.
20
- * Derived from the OpenAPI path by converting `{param}` tokens to `:param`.
38
+ * Express-style path string, for example `/pets/:petId`.
39
+ * OpenAPI `{param}` parts are converted to `:param`.
21
40
  */
22
41
  path: string
42
+ /**
43
+ * Group labels for the operation.
44
+ * Usually copied from OpenAPI `tags`.
45
+ */
23
46
  tags: Array<string>
47
+ /**
48
+ * Short one-line operation summary.
49
+ */
24
50
  summary?: string
51
+ /**
52
+ * Full operation description.
53
+ */
25
54
  description?: string
55
+ /**
56
+ * Marks the operation as deprecated.
57
+ */
26
58
  deprecated?: boolean
59
+ /**
60
+ * Parameters that could be used, we have QueryParams, PathParams, HeaderParams and CookieParams
61
+ */
27
62
  parameters: Array<ParameterNode>
28
63
  /**
29
- * Request body for OAS operations. Bundles the schema with optional keys to exclude.
64
+ * Request body metadata for the operation.
30
65
  */
31
66
  requestBody?: {
32
67
  /**
33
- * Human-readable description of the request body (maps to `requestBody.description` in OAS).
68
+ * Human-readable request body description.
34
69
  */
35
70
  description?: string
36
71
  /**
37
- * The request body schema. For OAS, this is the schema of the first content entry.
72
+ * Request body schema.
73
+ * For OpenAPI, this is the schema from the first `content` entry.
38
74
  */
39
75
  schema?: SchemaNode
40
76
  /**
41
77
  * Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
42
- * Populated when the schema is a `$ref` and the referenced schema has `readOnly` properties
43
- * that should not appear in request types.
78
+ * Set when a referenced schema has `readOnly` fields that should be omitted in request types.
44
79
  */
45
80
  keysToOmit?: Array<string>
46
81
  }
82
+ /**
83
+ * Operation responses.
84
+ */
47
85
  responses: Array<ResponseNode>
48
86
  }
@@ -4,12 +4,38 @@ import type { SchemaNode } from './schema.ts'
4
4
  export type ParameterLocation = 'path' | 'query' | 'header' | 'cookie'
5
5
 
6
6
  /**
7
- * A single input parameter for an operation.
7
+ * AST node representing one operation parameter.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const param: ParameterNode = {
12
+ * kind: 'Parameter',
13
+ * name: 'petId',
14
+ * in: 'path',
15
+ * schema: createSchema({ type: 'string' }),
16
+ * required: true,
17
+ * }
18
+ * ```
8
19
  */
9
20
  export type ParameterNode = BaseNode & {
21
+ /**
22
+ * Node kind.
23
+ */
10
24
  kind: 'Parameter'
25
+ /**
26
+ * Parameter name.
27
+ */
11
28
  name: string
29
+ /**
30
+ * Parameter location (`path`, `query`, `header`, or `cookie`).
31
+ */
12
32
  in: ParameterLocation
33
+ /**
34
+ * Parameter schema.
35
+ */
13
36
  schema: SchemaNode
37
+ /**
38
+ * Whether the parameter is required.
39
+ */
14
40
  required: boolean
15
41
  }
@@ -2,11 +2,33 @@ import type { BaseNode } from './base.ts'
2
2
  import type { SchemaNode } from './schema.ts'
3
3
 
4
4
  /**
5
- * A named property within an object schema.
5
+ * AST node representing one named object property.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const property: PropertyNode = {
10
+ * kind: 'Property',
11
+ * name: 'id',
12
+ * schema: createSchema({ type: 'integer' }),
13
+ * required: true,
14
+ * }
15
+ * ```
6
16
  */
7
17
  export type PropertyNode = BaseNode & {
18
+ /**
19
+ * Node kind.
20
+ */
8
21
  kind: 'Property'
22
+ /**
23
+ * Property key.
24
+ */
9
25
  name: string
26
+ /**
27
+ * Property schema.
28
+ */
10
29
  schema: SchemaNode
30
+ /**
31
+ * Whether the property is required.
32
+ */
11
33
  required: boolean
12
34
  }
@@ -3,21 +3,41 @@ import type { MediaType, StatusCode } from './http.ts'
3
3
  import type { SchemaNode } from './schema.ts'
4
4
 
5
5
  /**
6
- * A single response variant for an operation.
6
+ * AST node representing one operation response variant.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const response: ResponseNode = {
11
+ * kind: 'Response',
12
+ * statusCode: '200',
13
+ * schema: createSchema({ type: 'string' }),
14
+ * }
15
+ * ```
7
16
  */
8
17
  export type ResponseNode = BaseNode & {
18
+ /**
19
+ * Node kind.
20
+ */
9
21
  kind: 'Response'
10
22
  /**
11
23
  * HTTP status code or `'default'` for a fallback response.
12
24
  */
13
25
  statusCode: StatusCode
26
+ /**
27
+ * Optional response description.
28
+ */
14
29
  description?: string
30
+ /**
31
+ * Response body schema.
32
+ */
15
33
  schema: SchemaNode
34
+ /**
35
+ * Response media type.
36
+ */
16
37
  mediaType?: MediaType
17
38
  /**
18
39
  * Property keys to exclude from the generated type via `Omit<Type, Keys>`.
19
- * Populated when the response schema is a `$ref` and the referenced schema has
20
- * `writeOnly` properties that should not appear in response types.
40
+ * Set when a referenced schema has `writeOnly` fields that should not appear in response types.
21
41
  */
22
42
  keysToOmit?: Array<string>
23
43
  }
package/src/nodes/root.ts CHANGED
@@ -3,8 +3,13 @@ import type { OperationNode } from './operation.ts'
3
3
  import type { SchemaNode } from './schema.ts'
4
4
 
5
5
  /**
6
- * Format-agnostic metadata about the API document.
7
- * Adapters populate whichever fields are available in their source format.
6
+ * Basic metadata for an API document.
7
+ * Adapters fill fields that exist in their source format.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const meta: RootMeta = { title: 'Pet API', version: '1.0.0' }
12
+ * ```
8
13
  */
9
14
  export type RootMeta = {
10
15
  /**
@@ -20,23 +25,39 @@ export type RootMeta = {
20
25
  */
21
26
  version?: string
22
27
  /**
23
- * Resolved base URL for the API.
24
- * OAS: derived from `servers[serverIndex].url` with variable substitution.
25
- * AsyncAPI: derived from `servers[serverIndex].url`.
26
- * Drizzle / schema-only formats: not set.
28
+ * Resolved API base URL.
29
+ * For OpenAPI and AsyncAPI, this comes from the selected server URL.
27
30
  */
28
31
  baseURL?: string
29
32
  }
30
33
 
31
34
  /**
32
- * Top-level container for all schemas and operations in a single API document.
35
+ * Root AST node that contains all schemas and operations for one API document.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const root: RootNode = {
40
+ * kind: 'Root',
41
+ * schemas: [],
42
+ * operations: [],
43
+ * }
44
+ * ```
33
45
  */
34
46
  export type RootNode = BaseNode & {
47
+ /**
48
+ * Node kind.
49
+ */
35
50
  kind: 'Root'
51
+ /**
52
+ * All schema nodes in the document.
53
+ */
36
54
  schemas: Array<SchemaNode>
55
+ /**
56
+ * All operation nodes in the document.
57
+ */
37
58
  operations: Array<OperationNode>
38
59
  /**
39
- * Format-agnostic document metadata populated by the adapter.
60
+ * Optional document metadata populated by the adapter.
40
61
  */
41
62
  meta?: RootMeta
42
63
  }