@kubb/ast 5.0.0-beta.60 → 5.0.0-beta.62
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/README.md +2 -1
- package/dist/defineMacro-BryDiuQl.cjs +115 -0
- package/dist/defineMacro-BryDiuQl.cjs.map +1 -0
- package/dist/defineMacro-CNkUpxia.js +99 -0
- package/dist/defineMacro-CNkUpxia.js.map +1 -0
- package/dist/defineMacro-Vw-xQvq7.d.ts +467 -0
- package/dist/factory.cjs +64 -4
- package/dist/factory.cjs.map +1 -0
- package/dist/factory.d.ts +2 -37
- package/dist/factory.js +58 -3
- package/dist/factory.js.map +1 -0
- package/dist/{index-BzjwdK2M.d.ts → index-CTaN_ee_.d.ts} +235 -198
- package/dist/index.cjs +33 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +36 -36
- package/dist/index.js +19 -14
- package/dist/index.js.map +1 -1
- package/dist/macros.cjs +130 -0
- package/dist/macros.cjs.map +1 -0
- package/dist/macros.d.ts +61 -0
- package/dist/macros.js +128 -0
- package/dist/macros.js.map +1 -0
- package/dist/{operationParams-BZ07xDm0.d.ts → operationParams-B44p6EQy.d.ts} +2 -2
- package/dist/{response-DS5S3IG4.cjs → response-BeG6hq2D.cjs} +389 -173
- package/dist/response-BeG6hq2D.cjs.map +1 -0
- package/dist/{response-DKxTr522.js → response-Rd1uisM1.js} +377 -162
- package/dist/response-Rd1uisM1.js.map +1 -0
- package/dist/types-DQTgVSwE.d.ts +314 -0
- package/dist/types.d.ts +5 -5
- package/dist/{utils-D83JA6Xx.cjs → utils-BDI3kXlb.cjs} +20 -753
- package/dist/utils-BDI3kXlb.cjs.map +1 -0
- package/dist/{utils-Dj_KoXMv.js → utils-DW9rnfsD.js} +11 -630
- package/dist/utils-DW9rnfsD.js.map +1 -0
- package/dist/utils.cjs +11 -9
- package/dist/utils.d.ts +38 -4
- package/dist/utils.js +4 -3
- package/dist/visitor-B7Zlnp4c.cjs +604 -0
- package/dist/visitor-B7Zlnp4c.cjs.map +1 -0
- package/dist/visitor-DepQEKyp.js +510 -0
- package/dist/visitor-DepQEKyp.js.map +1 -0
- package/package.json +5 -1
- package/src/constants.ts +0 -30
- package/src/dedupe.ts +1 -9
- package/src/defineMacro.ts +139 -0
- package/src/{node.ts → defineNode.ts} +19 -42
- package/src/dialect.ts +42 -19
- package/src/factory.ts +3 -90
- package/src/index.ts +9 -15
- package/src/macros/index.ts +3 -0
- package/src/macros/macroDiscriminatorEnum.ts +50 -0
- package/src/macros/macroEnumName.ts +33 -0
- package/src/macros/macroSimplifyUnion.ts +60 -0
- package/src/nodes/code.ts +32 -75
- package/src/nodes/content.ts +2 -7
- package/src/nodes/file.ts +102 -14
- package/src/nodes/function.ts +46 -46
- package/src/nodes/index.ts +2 -3
- package/src/nodes/input.ts +13 -9
- package/src/nodes/operation.ts +5 -5
- package/src/nodes/output.ts +1 -1
- package/src/nodes/parameter.ts +6 -6
- package/src/nodes/property.ts +6 -6
- package/src/nodes/requestBody.ts +6 -13
- package/src/nodes/response.ts +93 -8
- package/src/nodes/schema.ts +1 -1
- package/src/registry.ts +1 -1
- package/src/types.ts +4 -4
- package/src/utils/extractStringsFromNodes.ts +1 -0
- package/src/utils/index.ts +2 -2
- package/src/utils/operationParams.ts +1 -1
- package/src/utils/refs.ts +27 -1
- package/src/utils/schemaMerge.ts +34 -0
- package/src/visitor.ts +2 -13
- package/dist/extractStringsFromNodes-WMYJ8nQL.d.ts +0 -82
- package/dist/factory-Cl8Z7mcc.cjs +0 -299
- package/dist/factory-Cl8Z7mcc.cjs.map +0 -1
- package/dist/factory-Du7nEP4B.js +0 -282
- package/dist/factory-Du7nEP4B.js.map +0 -1
- package/dist/response-DKxTr522.js.map +0 -1
- package/dist/response-DS5S3IG4.cjs.map +0 -1
- package/dist/types-olVl9v5p.d.ts +0 -764
- package/dist/utils-D83JA6Xx.cjs.map +0 -1
- package/dist/utils-Dj_KoXMv.js.map +0 -1
- package/src/mocks.ts +0 -56
- package/src/nodes/http.ts +0 -85
- package/src/transformers.ts +0 -191
- /package/src/{printer.ts → definePrinter.ts} +0 -0
package/src/nodes/requestBody.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineNode } from '../
|
|
1
|
+
import { defineNode } from '../defineNode.ts'
|
|
2
2
|
import type { BaseNode } from './base.ts'
|
|
3
|
-
import {
|
|
3
|
+
import type { ContentNode } from './content.ts'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* AST node representing an operation request body.
|
|
@@ -40,22 +40,15 @@ export type RequestBodyNode = BaseNode & {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Definition for the {@link RequestBodyNode}. Content entries are built upfront with
|
|
44
|
+
* {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes.
|
|
44
45
|
*/
|
|
45
|
-
export
|
|
46
|
-
content?: Array<UserContent>
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Definition for the {@link RequestBodyNode}, normalizing each content entry into a `ContentNode`.
|
|
51
|
-
*/
|
|
52
|
-
export const requestBodyDef = defineNode<RequestBodyNode, UserRequestBody>({
|
|
46
|
+
export const requestBodyDef = defineNode<RequestBodyNode>({
|
|
53
47
|
kind: 'RequestBody',
|
|
54
|
-
build: (props) => ({ ...props, content: props.content?.map(createContent) }),
|
|
55
48
|
children: ['content'],
|
|
56
49
|
})
|
|
57
50
|
|
|
58
51
|
/**
|
|
59
|
-
* Creates a `RequestBodyNode
|
|
52
|
+
* Creates a `RequestBodyNode`.
|
|
60
53
|
*/
|
|
61
54
|
export const createRequestBody = requestBodyDef.create
|
package/src/nodes/response.ts
CHANGED
|
@@ -1,9 +1,94 @@
|
|
|
1
|
-
import { defineNode } from '../
|
|
1
|
+
import { defineNode } from '../defineNode.ts'
|
|
2
2
|
import type { BaseNode } from './base.ts'
|
|
3
|
-
import { type ContentNode, createContent
|
|
4
|
-
import type { StatusCode } from './http.ts'
|
|
3
|
+
import { type ContentNode, createContent } from './content.ts'
|
|
5
4
|
import type { SchemaNode } from './schema.ts'
|
|
6
5
|
|
|
6
|
+
/**
|
|
7
|
+
* All supported HTTP status code literals as strings, as used in API specs
|
|
8
|
+
* (for example, `"200"` and `"404"`).
|
|
9
|
+
*/
|
|
10
|
+
type HttpStatusCode =
|
|
11
|
+
// 1xx Informational
|
|
12
|
+
| '100'
|
|
13
|
+
| '101'
|
|
14
|
+
| '102'
|
|
15
|
+
| '103'
|
|
16
|
+
// 2xx Success
|
|
17
|
+
| '200'
|
|
18
|
+
| '201'
|
|
19
|
+
| '202'
|
|
20
|
+
| '203'
|
|
21
|
+
| '204'
|
|
22
|
+
| '205'
|
|
23
|
+
| '206'
|
|
24
|
+
| '207'
|
|
25
|
+
| '208'
|
|
26
|
+
| '226'
|
|
27
|
+
// 3xx Redirection
|
|
28
|
+
| '300'
|
|
29
|
+
| '301'
|
|
30
|
+
| '302'
|
|
31
|
+
| '303'
|
|
32
|
+
| '304'
|
|
33
|
+
| '305'
|
|
34
|
+
| '307'
|
|
35
|
+
| '308'
|
|
36
|
+
// 4xx Client Error
|
|
37
|
+
| '400'
|
|
38
|
+
| '401'
|
|
39
|
+
| '402'
|
|
40
|
+
| '403'
|
|
41
|
+
| '404'
|
|
42
|
+
| '405'
|
|
43
|
+
| '406'
|
|
44
|
+
| '407'
|
|
45
|
+
| '408'
|
|
46
|
+
| '409'
|
|
47
|
+
| '410'
|
|
48
|
+
| '411'
|
|
49
|
+
| '412'
|
|
50
|
+
| '413'
|
|
51
|
+
| '414'
|
|
52
|
+
| '415'
|
|
53
|
+
| '416'
|
|
54
|
+
| '417'
|
|
55
|
+
| '418'
|
|
56
|
+
| '421'
|
|
57
|
+
| '422'
|
|
58
|
+
| '423'
|
|
59
|
+
| '424'
|
|
60
|
+
| '425'
|
|
61
|
+
| '426'
|
|
62
|
+
| '428'
|
|
63
|
+
| '429'
|
|
64
|
+
| '431'
|
|
65
|
+
| '451'
|
|
66
|
+
// 5xx Server Error
|
|
67
|
+
| '500'
|
|
68
|
+
| '501'
|
|
69
|
+
| '502'
|
|
70
|
+
| '503'
|
|
71
|
+
| '504'
|
|
72
|
+
| '505'
|
|
73
|
+
| '506'
|
|
74
|
+
| '507'
|
|
75
|
+
| '508'
|
|
76
|
+
| '510'
|
|
77
|
+
| '511'
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Response status code literal used by operations.
|
|
81
|
+
*
|
|
82
|
+
* Includes specific HTTP status code strings and `"default"` for catch-all responses.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const status: StatusCode = '200'
|
|
87
|
+
* const fallback: StatusCode = 'default'
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export type StatusCode = HttpStatusCode | 'default'
|
|
91
|
+
|
|
7
92
|
/**
|
|
8
93
|
* AST node representing one operation response variant.
|
|
9
94
|
*
|
|
@@ -16,7 +101,7 @@ import type { SchemaNode } from './schema.ts'
|
|
|
16
101
|
* const response: ResponseNode = {
|
|
17
102
|
* kind: 'Response',
|
|
18
103
|
* statusCode: '200',
|
|
19
|
-
* content: [{ contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
|
|
104
|
+
* content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
|
|
20
105
|
* }
|
|
21
106
|
* ```
|
|
22
107
|
*/
|
|
@@ -53,7 +138,7 @@ export type ResponseNode = BaseNode & {
|
|
|
53
138
|
|
|
54
139
|
type ResponseInput = Pick<ResponseNode, 'statusCode'> &
|
|
55
140
|
Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'content'>> & {
|
|
56
|
-
content?: Array<
|
|
141
|
+
content?: Array<ContentNode>
|
|
57
142
|
schema?: SchemaNode
|
|
58
143
|
mediaType?: string | null
|
|
59
144
|
keysToOmit?: Array<string> | null
|
|
@@ -67,8 +152,8 @@ export const responseDef = defineNode<ResponseNode, ResponseInput>({
|
|
|
67
152
|
kind: 'Response',
|
|
68
153
|
build: (props) => {
|
|
69
154
|
const { schema, mediaType, keysToOmit, content, ...rest } = props
|
|
70
|
-
const entries = content ?? (schema ? [{ contentType: mediaType ?? 'application/json', schema, keysToOmit: keysToOmit ?? null }] : undefined)
|
|
71
|
-
return { ...rest, content: entries
|
|
155
|
+
const entries = content ?? (schema ? [createContent({ contentType: mediaType ?? 'application/json', schema, keysToOmit: keysToOmit ?? null })] : undefined)
|
|
156
|
+
return { ...rest, content: entries }
|
|
72
157
|
},
|
|
73
158
|
children: ['content'],
|
|
74
159
|
visitorKey: 'response',
|
|
@@ -81,7 +166,7 @@ export const responseDef = defineNode<ResponseNode, ResponseInput>({
|
|
|
81
166
|
* ```ts
|
|
82
167
|
* const response = createResponse({
|
|
83
168
|
* statusCode: '200',
|
|
84
|
-
* content: [{ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) }],
|
|
169
|
+
* content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })],
|
|
85
170
|
* })
|
|
86
171
|
* ```
|
|
87
172
|
*/
|
package/src/nodes/schema.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { InferSchemaNode } from '../infer.ts'
|
|
2
|
-
import { defineNode, type DistributiveOmit } from '../
|
|
2
|
+
import { defineNode, type DistributiveOmit } from '../defineNode.ts'
|
|
3
3
|
import type { BaseNode } from './base.ts'
|
|
4
4
|
import type { PropertyNode } from './property.ts'
|
|
5
5
|
|
package/src/registry.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NodeDef } from './
|
|
1
|
+
import type { NodeDef } from './defineNode.ts'
|
|
2
2
|
import { arrowFunctionDef, breakDef, constDef, functionDef, jsxDef, textDef, typeDef } from './nodes/code.ts'
|
|
3
3
|
import { contentDef } from './nodes/content.ts'
|
|
4
4
|
import { exportDef, fileDef, importDef, sourceDef } from './nodes/file.ts'
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export type { DedupeCanonical, DedupeLookups, DedupePlan } from './dedupe.ts'
|
|
2
|
-
export type { SchemaDialect } from './dialect.ts'
|
|
3
|
-
export type { DistributiveOmit } from './
|
|
2
|
+
export type { Dialect, SchemaDialect } from './dialect.ts'
|
|
3
|
+
export type { DistributiveOmit, NodeDef } from './defineNode.ts'
|
|
4
4
|
export type { InferSchemaNode, ParserOptions } from './infer.ts'
|
|
5
5
|
export type * from './nodes/index.ts'
|
|
6
6
|
export type { ParentOf, Visitor, VisitorContext } from './visitor.ts'
|
|
7
|
-
export type { Printer, PrinterFactoryOptions, PrinterPartial } from './
|
|
7
|
+
export type { Printer, PrinterFactoryOptions, PrinterPartial } from './definePrinter.ts'
|
|
8
8
|
export type { OperationParamsResolver } from './utils/operationParams.ts'
|
|
9
|
-
export type {
|
|
9
|
+
export type { Enforce, Macro } from './defineMacro.ts'
|
|
@@ -8,6 +8,7 @@ import type { CodeNode } from '../nodes/code.ts'
|
|
|
8
8
|
*/
|
|
9
9
|
export function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string {
|
|
10
10
|
if (!nodes?.length) return ''
|
|
11
|
+
|
|
11
12
|
return nodes
|
|
12
13
|
.map((node) => {
|
|
13
14
|
// Backward-compat: compiled plugins may still pass bare strings at runtime
|
package/src/utils/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { isValidVarName } from '@internals/utils'
|
|
2
2
|
export { buildJSDoc, buildList, buildObject, objectKey } from './codegen.ts'
|
|
3
3
|
export { extractStringsFromNodes } from './extractStringsFromNodes.ts'
|
|
4
|
-
export { childName, enumPropName, extractRefName, isStringType, resolveGroupType, resolveRefName } from './refs.ts'
|
|
5
|
-
export {
|
|
4
|
+
export { childName, enumPropName, extractRefName, isStringType, resolveGroupType, resolveRefName, syncSchemaRef } from './refs.ts'
|
|
5
|
+
export { mergeAdjacentObjectsLazy } from './schemaMerge.ts'
|
|
6
6
|
export { getNestedAccessor, jsStringEscape, stringify, stringifyObject, toRegExpString, trimQuotes } from './strings.ts'
|
|
7
7
|
export { collectUsedSchemaNames, containsCircularRef, findCircularSchemas } from './schemaGraph.ts'
|
|
8
8
|
export { lazyGetter, mapSchemaItems, mapSchemaMembers, mapSchemaProperties } from './schemaTraversal.ts'
|
|
@@ -206,7 +206,7 @@ export function resolveParamType({
|
|
|
206
206
|
const groupName = groupLocation ? groupResolvers[groupLocation].call(resolver, node, param) : undefined
|
|
207
207
|
|
|
208
208
|
if (groupName && groupName !== individualName) {
|
|
209
|
-
return createIndexedAccessType({
|
|
209
|
+
return createIndexedAccessType({ target: groupName, key: param.name })
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
return individualName
|
package/src/utils/refs.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { pascalCase } from '@internals/utils'
|
|
2
2
|
import { narrowSchema } from '../guards.ts'
|
|
3
3
|
import type { OperationNode, ParameterNode, SchemaNode } from '../nodes/index.ts'
|
|
4
|
-
import type
|
|
4
|
+
import { createSchema, type SchemaType } from '../nodes/schema.ts'
|
|
5
5
|
import type { OperationParamsResolver, ParamGroupType } from './operationParams.ts'
|
|
6
6
|
|
|
7
7
|
const plainStringTypes = new Set<SchemaType>(['string', 'uuid', 'email', 'url', 'datetime'] as const)
|
|
@@ -63,6 +63,32 @@ export function enumPropName(parentName: string | null | undefined, propName: st
|
|
|
63
63
|
return pascalCase([parentName, propName, enumSuffix].filter(Boolean).join(' '))
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
68
|
+
*
|
|
69
|
+
* Usage-site fields (`description`, `readOnly`, `nullable`, `deprecated`) on the ref node override
|
|
70
|
+
* the same fields in the resolved `node.schema`. Non-ref nodes are returned unchanged.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
75
|
+
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export function syncSchemaRef(node: SchemaNode): SchemaNode {
|
|
79
|
+
const ref = narrowSchema(node, 'ref')
|
|
80
|
+
|
|
81
|
+
if (!ref) return node
|
|
82
|
+
if (!ref.schema) return node
|
|
83
|
+
|
|
84
|
+
const { kind: _kind, type: _type, name: _name, ref: _ref, schema: _schema, ...overrides } = ref
|
|
85
|
+
|
|
86
|
+
// Filter out undefined override values so they don't shadow the resolved schema's fields.
|
|
87
|
+
const definedOverrides = Object.fromEntries(Object.entries(overrides).filter(([, v]) => v !== undefined))
|
|
88
|
+
|
|
89
|
+
return createSchema({ ...ref.schema, ...definedOverrides })
|
|
90
|
+
}
|
|
91
|
+
|
|
66
92
|
/**
|
|
67
93
|
* Type guard that returns `true` when a schema emits as a plain `string` type.
|
|
68
94
|
*
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { narrowSchema } from '../guards.ts'
|
|
2
|
+
import { createSchema, type SchemaNode } from '../nodes/schema.ts'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Merges a run of adjacent anonymous object members into one. Named or non-object members break the
|
|
6
|
+
* run and pass through. Stays a construction-time helper, not a macro, so callers keep control of the
|
|
7
|
+
* member boundaries (such as keeping synthetic discriminant objects out of a run).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const merged = [...mergeAdjacentObjectsLazy([objectA, objectB])]
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function* mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined> {
|
|
15
|
+
let acc: SchemaNode | undefined
|
|
16
|
+
|
|
17
|
+
for (const member of members) {
|
|
18
|
+
const objectMember = narrowSchema(member, 'object')
|
|
19
|
+
if (objectMember && !objectMember.name && acc !== undefined) {
|
|
20
|
+
const accObject = narrowSchema(acc, 'object')
|
|
21
|
+
if (accObject && !accObject.name) {
|
|
22
|
+
acc = createSchema({
|
|
23
|
+
...accObject,
|
|
24
|
+
properties: [...(accObject.properties ?? []), ...(objectMember.properties ?? [])],
|
|
25
|
+
})
|
|
26
|
+
continue
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (acc !== undefined) yield acc
|
|
30
|
+
acc = member
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (acc !== undefined) yield acc
|
|
34
|
+
}
|
package/src/visitor.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { VisitorDepth } from './constants.ts'
|
|
2
2
|
import { visitorDepths, WALK_CONCURRENCY } from './constants.ts'
|
|
3
|
-
import type { NodeDef } from './
|
|
3
|
+
import type { NodeDef } from './defineNode.ts'
|
|
4
4
|
import type {
|
|
5
5
|
ContentNode,
|
|
6
6
|
InputNode,
|
|
@@ -32,14 +32,6 @@ const VISITOR_KEY_BY_KIND = Object.fromEntries(nodeDefs.flatMap((def) => (def.vi
|
|
|
32
32
|
Record<NodeKind, NonNullable<NodeDef['visitorKey']>>
|
|
33
33
|
>
|
|
34
34
|
|
|
35
|
-
/**
|
|
36
|
-
* Per-kind builders rerun after children are rebuilt. Derived from each
|
|
37
|
-
* definition's `rebuild` flag.
|
|
38
|
-
*/
|
|
39
|
-
const nodeRebuilders = Object.fromEntries(
|
|
40
|
-
nodeDefs.flatMap((def) => (def.rebuild ? [[def.kind, def.create as unknown as (node: Node) => Node] as const] : [])),
|
|
41
|
-
) as Partial<Record<NodeKind, (node: Node) => Node>>
|
|
42
|
-
|
|
43
35
|
/**
|
|
44
36
|
* Creates a small async concurrency limiter.
|
|
45
37
|
*
|
|
@@ -443,10 +435,7 @@ export function transform(node: Node, options: TransformOptions): Node {
|
|
|
443
435
|
// Structural sharing: when the visitor and child rebuild both left this node
|
|
444
436
|
// untouched, return the original reference so callers can detect "nothing
|
|
445
437
|
// changed" by identity and ancestors can avoid reallocating.
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
const rebuild = nodeRebuilders[rebuilt.kind]
|
|
449
|
-
return rebuild ? rebuild(rebuilt) : rebuilt
|
|
438
|
+
return rebuilt
|
|
450
439
|
}
|
|
451
440
|
|
|
452
441
|
/**
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { n as __name } from "./chunk-CNktS9qV.js";
|
|
2
|
-
import { Pt as CodeNode, _t as SchemaNode } from "./index-BzjwdK2M.js";
|
|
3
|
-
|
|
4
|
-
//#region src/transformers.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Replaces a discriminator property's schema with a string enum of allowed values.
|
|
7
|
-
*
|
|
8
|
-
* If `node` is not an object schema, or if the property does not exist, the input
|
|
9
|
-
* node is returned as-is.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const schema = createSchema({
|
|
14
|
-
* type: 'object',
|
|
15
|
-
* properties: [createProperty({ name: 'type', required: true, schema: createSchema({ type: 'string' }) })],
|
|
16
|
-
* })
|
|
17
|
-
* const result = setDiscriminatorEnum({ node: schema, propertyName: 'type', values: ['dog', 'cat'] })
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
declare function setDiscriminatorEnum({
|
|
21
|
-
node,
|
|
22
|
-
propertyName,
|
|
23
|
-
values,
|
|
24
|
-
enumName
|
|
25
|
-
}: {
|
|
26
|
-
node: SchemaNode;
|
|
27
|
-
propertyName: string;
|
|
28
|
-
values: Array<string>;
|
|
29
|
-
enumName?: string;
|
|
30
|
-
}): SchemaNode;
|
|
31
|
-
/**
|
|
32
|
-
* Merges adjacent anonymous object members into a single anonymous object member.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* const merged = mergeAdjacentObjects([
|
|
37
|
-
* createSchema({ type: 'object', properties: [createProperty({ name: 'a', schema: createSchema({ type: 'string' }) })] }),
|
|
38
|
-
* createSchema({ type: 'object', properties: [createProperty({ name: 'b', schema: createSchema({ type: 'number' }) })] }),
|
|
39
|
-
* ])
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined>;
|
|
43
|
-
/**
|
|
44
|
-
* Removes enum members that are covered by broader scalar primitives in the same union.
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```ts
|
|
48
|
-
* const simplified = simplifyUnion([
|
|
49
|
-
* createSchema({ type: 'enum', primitive: 'string', enumValues: ['active'] }),
|
|
50
|
-
* createSchema({ type: 'string' }),
|
|
51
|
-
* ])
|
|
52
|
-
* // keeps only string member
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
declare function simplifyUnion(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
56
|
-
declare function setEnumName(propNode: SchemaNode, parentName: string | null | undefined, propName: string, enumSuffix: string): SchemaNode;
|
|
57
|
-
/**
|
|
58
|
-
* Merges a ref node with its resolved schema, giving usage-site fields precedence.
|
|
59
|
-
*
|
|
60
|
-
* Usage-site fields (`description`, `readOnly`, `nullable`, `deprecated`) on the ref node override
|
|
61
|
-
* the same fields in the resolved `node.schema`. Non-ref nodes are returned unchanged.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```ts
|
|
65
|
-
* // Ref with description override
|
|
66
|
-
* const ref = createSchema({ type: 'ref', ref: '#/components/schemas/Pet', description: 'A cute pet' })
|
|
67
|
-
* const merged = syncSchemaRef(ref) // merges with resolved Pet schema
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
declare function syncSchemaRef(node: SchemaNode): SchemaNode;
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/utils/extractStringsFromNodes.d.ts
|
|
73
|
-
/**
|
|
74
|
-
* Extracts all string content from a `CodeNode` tree recursively.
|
|
75
|
-
*
|
|
76
|
-
* Collects text node values, identifier references in string fields (`params`, `generics`, `returnType`, `type`),
|
|
77
|
-
* and nested node content. Used to build the full source string for import filtering.
|
|
78
|
-
*/
|
|
79
|
-
declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): string;
|
|
80
|
-
//#endregion
|
|
81
|
-
export { simplifyUnion as a, setEnumName as i, mergeAdjacentObjectsLazy as n, syncSchemaRef as o, setDiscriminatorEnum as r, extractStringsFromNodes as t };
|
|
82
|
-
//# sourceMappingURL=extractStringsFromNodes-WMYJ8nQL.d.ts.map
|