@kubb/ast 5.0.0-alpha.3 → 5.0.0-alpha.30
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 +1123 -163
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +283 -17
- package/dist/index.js +1102 -154
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/visitor-z-5U8NoF.d.ts +2200 -0
- package/package.json +3 -2
- package/src/constants.ts +118 -4
- package/src/factory.ts +332 -18
- package/src/guards.ts +63 -8
- package/src/index.ts +25 -7
- package/src/infer.ts +130 -0
- package/src/mocks.ts +12 -5
- package/src/nodes/base.ts +32 -4
- package/src/nodes/function.ts +201 -0
- package/src/nodes/http.ts +17 -5
- package/src/nodes/index.ts +21 -5
- package/src/nodes/operation.ts +69 -6
- package/src/nodes/parameter.ts +27 -1
- package/src/nodes/property.ts +23 -1
- package/src/nodes/response.ts +29 -3
- package/src/nodes/root.ts +41 -10
- package/src/nodes/schema.ts +440 -42
- package/src/printer.ts +172 -60
- package/src/refs.ts +36 -4
- package/src/resolvers.ts +45 -0
- package/src/transformers.ts +156 -0
- package/src/types.ts +13 -2
- package/src/utils.ts +431 -4
- package/src/visitor.ts +378 -81
- package/dist/visitor-oFfdU8QA.d.ts +0 -653
package/src/nodes/property.ts
CHANGED
|
@@ -2,11 +2,33 @@ import type { BaseNode } from './base.ts'
|
|
|
2
2
|
import type { SchemaNode } from './schema.ts'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
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
|
}
|
package/src/nodes/response.ts
CHANGED
|
@@ -3,15 +3,41 @@ import type { MediaType, StatusCode } from './http.ts'
|
|
|
3
3
|
import type { SchemaNode } from './schema.ts'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Response body schema.
|
|
32
|
+
*/
|
|
33
|
+
schema: SchemaNode
|
|
34
|
+
/**
|
|
35
|
+
* Response media type.
|
|
36
|
+
*/
|
|
37
|
+
mediaType?: MediaType | null
|
|
38
|
+
/**
|
|
39
|
+
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
40
|
+
* Set when a referenced schema has `writeOnly` fields that should not appear in response types.
|
|
41
|
+
*/
|
|
42
|
+
keysToOmit?: Array<string>
|
|
17
43
|
}
|
package/src/nodes/root.ts
CHANGED
|
@@ -3,30 +3,61 @@ import type { OperationNode } from './operation.ts'
|
|
|
3
3
|
import type { SchemaNode } from './schema.ts'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Adapters
|
|
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
|
+
/**
|
|
16
|
+
* API title (from `info.title` in OAS/AsyncAPI).
|
|
17
|
+
*/
|
|
11
18
|
title?: string
|
|
12
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* API description (from `info.description` in OAS/AsyncAPI).
|
|
21
|
+
*/
|
|
22
|
+
description?: string
|
|
23
|
+
/**
|
|
24
|
+
* API version string (from `info.version` in OAS/AsyncAPI).
|
|
25
|
+
*/
|
|
13
26
|
version?: string
|
|
14
27
|
/**
|
|
15
|
-
* Resolved base URL
|
|
16
|
-
*
|
|
17
|
-
* AsyncAPI: derived from `servers[serverIndex].url`.
|
|
18
|
-
* Drizzle / schema-only formats: not set.
|
|
28
|
+
* Resolved API base URL.
|
|
29
|
+
* For OpenAPI and AsyncAPI, this comes from the selected server URL.
|
|
19
30
|
*/
|
|
20
31
|
baseURL?: string
|
|
21
32
|
}
|
|
22
33
|
|
|
23
34
|
/**
|
|
24
|
-
*
|
|
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
|
+
* ```
|
|
25
45
|
*/
|
|
26
46
|
export type RootNode = BaseNode & {
|
|
47
|
+
/**
|
|
48
|
+
* Node kind.
|
|
49
|
+
*/
|
|
27
50
|
kind: 'Root'
|
|
51
|
+
/**
|
|
52
|
+
* All schema nodes in the document.
|
|
53
|
+
*/
|
|
28
54
|
schemas: Array<SchemaNode>
|
|
55
|
+
/**
|
|
56
|
+
* All operation nodes in the document.
|
|
57
|
+
*/
|
|
29
58
|
operations: Array<OperationNode>
|
|
30
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Optional document metadata populated by the adapter.
|
|
61
|
+
*/
|
|
31
62
|
meta?: RootMeta
|
|
32
63
|
}
|