@kubb/ast 5.0.0-beta.2 → 5.0.0-beta.21
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 +1 -1
- package/dist/index.cjs +270 -206
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +118 -95
- package/dist/index.js +268 -207
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
- package/src/factory.ts +15 -0
- package/src/guards.ts +3 -3
- package/src/index.ts +3 -2
- package/src/nodes/index.ts +1 -1
- package/src/nodes/operation.ts +1 -1
- package/src/nodes/response.ts +1 -1
- package/src/nodes/root.ts +72 -10
- package/src/nodes/schema.ts +9 -3
- package/src/printer.ts +15 -16
- package/src/refs.ts +4 -2
- package/src/resolvers.ts +4 -4
- package/src/transformers.ts +20 -15
- package/src/types.ts +1 -0
- package/src/utils.ts +89 -56
- package/src/visitor.ts +133 -181
package/dist/index.d.ts
CHANGED
|
@@ -1120,6 +1120,10 @@ type SchemaNodeBase = BaseNode & {
|
|
|
1120
1120
|
* For example, this is `'string'` for a `uuid` schema.
|
|
1121
1121
|
*/
|
|
1122
1122
|
primitive?: PrimitiveSchemaType;
|
|
1123
|
+
/**
|
|
1124
|
+
* Schema `format` value.
|
|
1125
|
+
*/
|
|
1126
|
+
format?: string;
|
|
1123
1127
|
};
|
|
1124
1128
|
/**
|
|
1125
1129
|
* Object schema with ordered properties.
|
|
@@ -1322,8 +1326,9 @@ type RefSchemaNode = SchemaNodeBase & {
|
|
|
1322
1326
|
type: 'ref';
|
|
1323
1327
|
/**
|
|
1324
1328
|
* Referenced schema name.
|
|
1329
|
+
* `null` means Kubb has processed this and determined there is no applicable name.
|
|
1325
1330
|
*/
|
|
1326
|
-
name?: string;
|
|
1331
|
+
name?: string | null;
|
|
1327
1332
|
/**
|
|
1328
1333
|
* Original `$ref` path, for example, `#/components/schemas/Order`.
|
|
1329
1334
|
* Used to resolve names later.
|
|
@@ -1336,12 +1341,13 @@ type RefSchemaNode = SchemaNodeBase & {
|
|
|
1336
1341
|
/**
|
|
1337
1342
|
* The fully-parsed schema that this ref resolves to.
|
|
1338
1343
|
* Populated during OAS parsing when the referenced definition can be resolved.
|
|
1339
|
-
* `
|
|
1344
|
+
* `null` when the ref cannot be resolved or is part of a circular chain.
|
|
1345
|
+
* `undefined` when resolution has not been attempted.
|
|
1340
1346
|
*
|
|
1341
1347
|
* Useful for inspecting the referenced schema's structure (e.g. `primitive`, `properties`)
|
|
1342
1348
|
* without following the reference manually.
|
|
1343
1349
|
*/
|
|
1344
|
-
schema?: SchemaNode;
|
|
1350
|
+
schema?: SchemaNode | null;
|
|
1345
1351
|
};
|
|
1346
1352
|
/**
|
|
1347
1353
|
* Datetime schema.
|
|
@@ -1689,7 +1695,7 @@ type ResponseNode = BaseNode & {
|
|
|
1689
1695
|
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
1690
1696
|
* Set when a referenced schema has `writeOnly` fields that should not appear in response types.
|
|
1691
1697
|
*/
|
|
1692
|
-
keysToOmit?: Array<string
|
|
1698
|
+
keysToOmit?: Array<string> | null;
|
|
1693
1699
|
};
|
|
1694
1700
|
//#endregion
|
|
1695
1701
|
//#region src/nodes/operation.d.ts
|
|
@@ -1790,7 +1796,7 @@ type OperationNode = BaseNode & {
|
|
|
1790
1796
|
* Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
|
|
1791
1797
|
* Set when a referenced schema has `readOnly` fields that should be omitted in request types.
|
|
1792
1798
|
*/
|
|
1793
|
-
keysToOmit?: Array<string
|
|
1799
|
+
keysToOmit?: Array<string> | null;
|
|
1794
1800
|
}>;
|
|
1795
1801
|
};
|
|
1796
1802
|
/**
|
|
@@ -1826,32 +1832,62 @@ type OutputNode = BaseNode & {
|
|
|
1826
1832
|
//#endregion
|
|
1827
1833
|
//#region src/nodes/root.d.ts
|
|
1828
1834
|
/**
|
|
1829
|
-
*
|
|
1830
|
-
*
|
|
1835
|
+
* Metadata for an API document, populated by the adapter and available to every generator.
|
|
1836
|
+
*
|
|
1837
|
+
* All fields are plain JSON-serializable values — no `Set`, no `Map`, no class instances.
|
|
1838
|
+
* Computed fields (`circularNames`, `enumNames`) are pre-calculated once during the adapter
|
|
1839
|
+
* pre-scan so generators never need to iterate the full schema list themselves.
|
|
1831
1840
|
*
|
|
1832
1841
|
* @example
|
|
1833
1842
|
* ```ts
|
|
1834
|
-
* const meta: InputMeta = { title: 'Pet
|
|
1843
|
+
* const meta: InputMeta = { title: 'Pet Store', version: '1.0.0', baseURL: 'https://petstore.swagger.io/v2', circularNames: [], enumNames: [] }
|
|
1835
1844
|
* ```
|
|
1836
1845
|
*/
|
|
1837
1846
|
type InputMeta = {
|
|
1838
1847
|
/**
|
|
1839
|
-
* API title
|
|
1848
|
+
* API title from `info.title` in the source document.
|
|
1840
1849
|
*/
|
|
1841
1850
|
title?: string;
|
|
1842
1851
|
/**
|
|
1843
|
-
* API description
|
|
1852
|
+
* API description from `info.description` in the source document.
|
|
1844
1853
|
*/
|
|
1845
1854
|
description?: string;
|
|
1846
1855
|
/**
|
|
1847
|
-
* API version string
|
|
1856
|
+
* API version string from `info.version` in the source document.
|
|
1848
1857
|
*/
|
|
1849
1858
|
version?: string;
|
|
1850
1859
|
/**
|
|
1851
|
-
* Resolved
|
|
1852
|
-
|
|
1860
|
+
* Resolved base URL from the first matching server entry in the source document.
|
|
1861
|
+
*/
|
|
1862
|
+
baseURL?: string | null;
|
|
1863
|
+
/**
|
|
1864
|
+
* Names of schemas that participate in a circular reference chain.
|
|
1865
|
+
* Computed once during the adapter pre-scan — use this instead of calling
|
|
1866
|
+
* `findCircularSchemas` per generator call.
|
|
1867
|
+
*
|
|
1868
|
+
* Convert to a `Set` once at the start of a generator, not per-schema,
|
|
1869
|
+
* to keep lookup O(1) without repeated allocations.
|
|
1870
|
+
*
|
|
1871
|
+
* @example Wrap a circular schema in z.lazy()
|
|
1872
|
+
* ```ts
|
|
1873
|
+
* const circular = new Set(meta.circularNames)
|
|
1874
|
+
* if (circular.has(schema.name)) { ... }
|
|
1875
|
+
* ```
|
|
1876
|
+
*/
|
|
1877
|
+
circularNames: readonly string[];
|
|
1878
|
+
/**
|
|
1879
|
+
* Names of schemas whose type is `enum`.
|
|
1880
|
+
* Computed once during the adapter pre-scan — use this instead of filtering
|
|
1881
|
+
* schemas per generator call.
|
|
1882
|
+
*
|
|
1883
|
+
* Convert to a `Set` once at the start of a generator when you need repeated
|
|
1884
|
+
* membership checks, rather than calling `.includes()` per schema.
|
|
1885
|
+
*
|
|
1886
|
+
* @example Check if a referenced schema is an enum
|
|
1887
|
+
* `const enums = new Set(meta.enumNames)`
|
|
1888
|
+
* `const isEnum = enums.has(schemaName)`
|
|
1853
1889
|
*/
|
|
1854
|
-
|
|
1890
|
+
enumNames: readonly string[];
|
|
1855
1891
|
};
|
|
1856
1892
|
/**
|
|
1857
1893
|
* Input AST node that contains all schemas and operations for one API document.
|
|
@@ -1880,7 +1916,38 @@ type InputNode = BaseNode & {
|
|
|
1880
1916
|
*/
|
|
1881
1917
|
operations: Array<OperationNode>;
|
|
1882
1918
|
/**
|
|
1883
|
-
*
|
|
1919
|
+
* Document metadata populated by the adapter.
|
|
1920
|
+
*/
|
|
1921
|
+
meta: InputMeta;
|
|
1922
|
+
};
|
|
1923
|
+
/**
|
|
1924
|
+
* Streaming variant of `InputNode` for memory-efficient processing of large API specs.
|
|
1925
|
+
*
|
|
1926
|
+
* `schemas` and `operations` are `AsyncIterable` rather than arrays — each `for await`
|
|
1927
|
+
* loop creates a fresh parse pass from the cached in-memory document, so multiple
|
|
1928
|
+
* consumers (plugins) can iterate independently without keeping all nodes in memory.
|
|
1929
|
+
*
|
|
1930
|
+
* @example
|
|
1931
|
+
* ```ts
|
|
1932
|
+
* for await (const schema of inputStreamNode.schemas) {
|
|
1933
|
+
* // only this one SchemaNode is live here; previous ones are GC-eligible
|
|
1934
|
+
* }
|
|
1935
|
+
* ```
|
|
1936
|
+
*/
|
|
1937
|
+
type InputStreamNode = {
|
|
1938
|
+
kind: 'Input';
|
|
1939
|
+
/**
|
|
1940
|
+
* Lazily parsed schema nodes. Each `for await` creates a fresh parse pass, so
|
|
1941
|
+
* multiple plugins can iterate independently without sharing state.
|
|
1942
|
+
*/
|
|
1943
|
+
schemas: AsyncIterable<SchemaNode>;
|
|
1944
|
+
/**
|
|
1945
|
+
* Lazily parsed operation nodes. Each `for await` creates a fresh parse pass, so
|
|
1946
|
+
* multiple plugins can iterate independently without sharing state.
|
|
1947
|
+
*/
|
|
1948
|
+
operations: AsyncIterable<OperationNode>;
|
|
1949
|
+
/**
|
|
1950
|
+
* Document metadata available immediately, before the first yielded node.
|
|
1884
1951
|
*/
|
|
1885
1952
|
meta?: InputMeta;
|
|
1886
1953
|
};
|
|
@@ -2092,6 +2159,15 @@ type CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {
|
|
|
2092
2159
|
* ```
|
|
2093
2160
|
*/
|
|
2094
2161
|
declare function createInput(overrides?: Partial<Omit<InputNode, 'kind'>>): InputNode;
|
|
2162
|
+
/**
|
|
2163
|
+
* Creates an `InputStreamNode` from pre-built `AsyncIterable` sources.
|
|
2164
|
+
*
|
|
2165
|
+
* @example
|
|
2166
|
+
* ```ts
|
|
2167
|
+
* const node = createStreamInput(schemasIterable, operationsIterable, { title: 'My API' })
|
|
2168
|
+
* ```
|
|
2169
|
+
*/
|
|
2170
|
+
declare function createStreamInput(schemas: AsyncIterable<SchemaNode>, operations: AsyncIterable<OperationNode>, meta?: InputMeta): InputStreamNode;
|
|
2095
2171
|
/**
|
|
2096
2172
|
* Creates an `OutputNode` with a stable default for `files`.
|
|
2097
2173
|
*
|
|
@@ -2583,10 +2659,10 @@ declare function createJsx(value: string): JsxNode;
|
|
|
2583
2659
|
* @example
|
|
2584
2660
|
* ```ts
|
|
2585
2661
|
* const schema = createSchema({ type: 'string' })
|
|
2586
|
-
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode |
|
|
2662
|
+
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
|
|
2587
2663
|
* ```
|
|
2588
2664
|
*/
|
|
2589
|
-
declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] |
|
|
2665
|
+
declare function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | undefined, type: T): SchemaNodeByType[T] | null;
|
|
2590
2666
|
/**
|
|
2591
2667
|
* Returns `true` when the input is an `InputNode`.
|
|
2592
2668
|
*
|
|
@@ -2651,7 +2727,7 @@ type PrinterHandlerContext<TOutput, TOptions extends object> = {
|
|
|
2651
2727
|
* Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.
|
|
2652
2728
|
* Use `this.transform` inside `nodes` handlers and inside the `print` override.
|
|
2653
2729
|
*/
|
|
2654
|
-
transform: (node: SchemaNode) => TOutput | null
|
|
2730
|
+
transform: (node: SchemaNode) => TOutput | null;
|
|
2655
2731
|
/**
|
|
2656
2732
|
* Options for this printer instance.
|
|
2657
2733
|
*/
|
|
@@ -2669,7 +2745,7 @@ type PrinterHandlerContext<TOutput, TOptions extends object> = {
|
|
|
2669
2745
|
* }
|
|
2670
2746
|
* ```
|
|
2671
2747
|
*/
|
|
2672
|
-
type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null
|
|
2748
|
+
type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null;
|
|
2673
2749
|
/**
|
|
2674
2750
|
* Partial map of per-node-type handler overrides for a printer.
|
|
2675
2751
|
*
|
|
@@ -2732,13 +2808,13 @@ type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
|
|
|
2732
2808
|
* Always dispatches through the `nodes` map; never calls the `print` override.
|
|
2733
2809
|
* Use this when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
|
|
2734
2810
|
*/
|
|
2735
|
-
transform: (node: SchemaNode) => T['output'] | null
|
|
2811
|
+
transform: (node: SchemaNode) => T['output'] | null;
|
|
2736
2812
|
/**
|
|
2737
2813
|
* Public printer. If the builder provides a root-level `print`, this calls that
|
|
2738
2814
|
* higher-level function (which may produce full declarations).
|
|
2739
2815
|
* Otherwise, falls back to the node-level dispatcher.
|
|
2740
2816
|
*/
|
|
2741
|
-
print: (node: SchemaNode) => T['printOutput'] | null
|
|
2817
|
+
print: (node: SchemaNode) => T['printOutput'] | null;
|
|
2742
2818
|
};
|
|
2743
2819
|
/**
|
|
2744
2820
|
* Builder function passed to `definePrinter`.
|
|
@@ -2811,22 +2887,22 @@ declare function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryO
|
|
|
2811
2887
|
* )
|
|
2812
2888
|
* ```
|
|
2813
2889
|
*/
|
|
2814
|
-
declare function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey |
|
|
2890
|
+
declare function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | null): <T extends PrinterFactoryOptions>(build: (options: T["options"]) => {
|
|
2815
2891
|
name: T["name"];
|
|
2816
2892
|
options: T["options"];
|
|
2817
2893
|
nodes: Partial<{ [K in TKey]: (this: {
|
|
2818
|
-
transform: (node: TNode) => T["output"] | null
|
|
2894
|
+
transform: (node: TNode) => T["output"] | null;
|
|
2819
2895
|
options: T["options"];
|
|
2820
|
-
}, node: TNodeByKey[K]) => T["output"] | null
|
|
2896
|
+
}, node: TNodeByKey[K]) => T["output"] | null }>;
|
|
2821
2897
|
print?: (this: {
|
|
2822
|
-
transform: (node: TNode) => T["output"] | null
|
|
2898
|
+
transform: (node: TNode) => T["output"] | null;
|
|
2823
2899
|
options: T["options"];
|
|
2824
|
-
}, node: TNode) => T["printOutput"] | null
|
|
2900
|
+
}, node: TNode) => T["printOutput"] | null;
|
|
2825
2901
|
}) => (options?: T["options"]) => {
|
|
2826
2902
|
name: T["name"];
|
|
2827
2903
|
options: T["options"];
|
|
2828
|
-
transform: (node: TNode) => T["output"] | null
|
|
2829
|
-
print: (node: TNode) => T["printOutput"] | null
|
|
2904
|
+
transform: (node: TNode) => T["output"] | null;
|
|
2905
|
+
print: (node: TNode) => T["printOutput"] | null;
|
|
2830
2906
|
};
|
|
2831
2907
|
//#endregion
|
|
2832
2908
|
//#region src/refs.d.ts
|
|
@@ -2860,7 +2936,7 @@ declare function collectImports<TImport>({
|
|
|
2860
2936
|
}: {
|
|
2861
2937
|
node: SchemaNode;
|
|
2862
2938
|
nameMapping: Map<string, string>;
|
|
2863
|
-
resolve: (schemaName: string) => TImport |
|
|
2939
|
+
resolve: (schemaName: string) => TImport | null;
|
|
2864
2940
|
}): Array<TImport>;
|
|
2865
2941
|
//#endregion
|
|
2866
2942
|
//#region src/transformers.d.ts
|
|
@@ -2901,6 +2977,7 @@ declare function setDiscriminatorEnum({
|
|
|
2901
2977
|
* ])
|
|
2902
2978
|
* ```
|
|
2903
2979
|
*/
|
|
2980
|
+
declare function mergeAdjacentObjectsLazy(members: Iterable<SchemaNode>): Generator<SchemaNode, void, undefined>;
|
|
2904
2981
|
declare function mergeAdjacentObjects(members: Array<SchemaNode>): Array<SchemaNode>;
|
|
2905
2982
|
/**
|
|
2906
2983
|
* Removes enum members that are covered by broader scalar primitives in the same union.
|
|
@@ -3028,13 +3105,13 @@ type AsyncVisitor = {
|
|
|
3028
3105
|
* ```
|
|
3029
3106
|
*/
|
|
3030
3107
|
type CollectVisitor<T> = {
|
|
3031
|
-
input?(node: InputNode, context: VisitorContext<InputNode>): T | undefined;
|
|
3032
|
-
output?(node: OutputNode, context: VisitorContext<OutputNode>): T | undefined;
|
|
3033
|
-
operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | undefined;
|
|
3034
|
-
schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | undefined;
|
|
3035
|
-
property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | undefined;
|
|
3036
|
-
parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | undefined;
|
|
3037
|
-
response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | undefined;
|
|
3108
|
+
input?(node: InputNode, context: VisitorContext<InputNode>): T | null | undefined;
|
|
3109
|
+
output?(node: OutputNode, context: VisitorContext<OutputNode>): T | null | undefined;
|
|
3110
|
+
operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | null | undefined;
|
|
3111
|
+
schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | null | undefined;
|
|
3112
|
+
property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | null | undefined;
|
|
3113
|
+
parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | null | undefined;
|
|
3114
|
+
response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | null | undefined;
|
|
3038
3115
|
};
|
|
3039
3116
|
/**
|
|
3040
3117
|
* Options for `transform`.
|
|
@@ -3153,7 +3230,7 @@ declare function transform(node: Node, options: TransformOptions): Node;
|
|
|
3153
3230
|
/**
|
|
3154
3231
|
* Runs a depth-first synchronous collection pass.
|
|
3155
3232
|
*
|
|
3156
|
-
* Non-`
|
|
3233
|
+
* Non-`null` values returned by visitor callbacks are appended to the result.
|
|
3157
3234
|
*
|
|
3158
3235
|
* @example
|
|
3159
3236
|
* ```ts
|
|
@@ -3170,6 +3247,7 @@ declare function transform(node: Node, options: TransformOptions): Node;
|
|
|
3170
3247
|
* const values = collect(root, { depth: 'shallow', root: () => 'root' })
|
|
3171
3248
|
* ```
|
|
3172
3249
|
*/
|
|
3250
|
+
declare function collectLazy<T>(node: Node, options: CollectOptions<T>): Generator<T, void, undefined>;
|
|
3173
3251
|
declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
|
|
3174
3252
|
//#endregion
|
|
3175
3253
|
//#region src/utils.d.ts
|
|
@@ -3194,13 +3272,6 @@ declare function syncSchemaRef(node: SchemaNode): SchemaNode;
|
|
|
3194
3272
|
* types, returns `true` only when `representation` is `'string'` rather than `'date'`.
|
|
3195
3273
|
*/
|
|
3196
3274
|
declare function isStringType(node: SchemaNode): boolean;
|
|
3197
|
-
/**
|
|
3198
|
-
* Applies casing rules to parameter names and returns a new parameter array.
|
|
3199
|
-
*
|
|
3200
|
-
* Use this before passing parameters to schema builders so output property keys match
|
|
3201
|
-
* the desired casing while preserving `OperationNode.parameters` for other consumers.
|
|
3202
|
-
* The input array is not mutated. When `casing` is not set, the original array is returned unchanged.
|
|
3203
|
-
*/
|
|
3204
3275
|
declare function caseParams(params: Array<ParameterNode>, casing: 'camelcase' | undefined): Array<ParameterNode>;
|
|
3205
3276
|
/**
|
|
3206
3277
|
* Creates a single-property object schema used as a discriminator literal.
|
|
@@ -3361,7 +3432,7 @@ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): st
|
|
|
3361
3432
|
/**
|
|
3362
3433
|
* Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
|
|
3363
3434
|
*
|
|
3364
|
-
* Returns `
|
|
3435
|
+
* Returns `null` for non-ref nodes or when no name can be resolved. Use this to get a schema's
|
|
3365
3436
|
* identifier for type definitions or error messages.
|
|
3366
3437
|
*
|
|
3367
3438
|
* @example
|
|
@@ -3370,56 +3441,8 @@ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): st
|
|
|
3370
3441
|
* // => 'Pet'
|
|
3371
3442
|
* ```
|
|
3372
3443
|
*/
|
|
3373
|
-
declare function resolveRefName(node: SchemaNode | undefined): string |
|
|
3374
|
-
/**
|
|
3375
|
-
* Collects every named schema referenced (transitively) from a node via ref edges.
|
|
3376
|
-
*
|
|
3377
|
-
* Refs are followed by name only — the resolved `node.schema` is not traversed inline.
|
|
3378
|
-
* Use this to determine schema dependencies, build reference graphs, or detect what schemas need to be emitted.
|
|
3379
|
-
*
|
|
3380
|
-
* @example Collect refs from a single schema
|
|
3381
|
-
* ```ts
|
|
3382
|
-
* const names = collectReferencedSchemaNames(petSchema)
|
|
3383
|
-
* // → Set { 'Category', 'Tag' }
|
|
3384
|
-
* ```
|
|
3385
|
-
*
|
|
3386
|
-
* @example Accumulate refs from multiple schemas into one set
|
|
3387
|
-
* ```ts
|
|
3388
|
-
* const out = new Set<string>()
|
|
3389
|
-
* for (const schema of schemas) {
|
|
3390
|
-
* collectReferencedSchemaNames(schema, out)
|
|
3391
|
-
* }
|
|
3392
|
-
* ```
|
|
3393
|
-
*/
|
|
3444
|
+
declare function resolveRefName(node: SchemaNode | undefined): string | null;
|
|
3394
3445
|
declare function collectReferencedSchemaNames(node: SchemaNode | undefined, out?: Set<string>): Set<string>;
|
|
3395
|
-
/**
|
|
3396
|
-
* Collects the names of all top-level schemas transitively used by a set of operations.
|
|
3397
|
-
*
|
|
3398
|
-
* An operation uses a schema when any of its parameters, request body content, or responses
|
|
3399
|
-
* reference it — directly or indirectly through other named schemas.
|
|
3400
|
-
* The walk is iterative and safe against reference cycles.
|
|
3401
|
-
*
|
|
3402
|
-
* Use this together with `include` filters to determine which schemas from `components/schemas`
|
|
3403
|
-
* are reachable from the allowed operations, so that schemas used only by excluded operations
|
|
3404
|
-
* are not generated.
|
|
3405
|
-
*
|
|
3406
|
-
* @example Only generate schemas referenced by included operations
|
|
3407
|
-
* ```ts
|
|
3408
|
-
* const includedOps = inputNode.operations.filter(op => resolver.resolveOptions(op, { options, include }) !== null)
|
|
3409
|
-
* const allowed = collectUsedSchemaNames(includedOps, inputNode.schemas)
|
|
3410
|
-
*
|
|
3411
|
-
* for (const schema of inputNode.schemas) {
|
|
3412
|
-
* if (schema.name && !allowed.has(schema.name)) continue
|
|
3413
|
-
* // … generate schema
|
|
3414
|
-
* }
|
|
3415
|
-
* ```
|
|
3416
|
-
*
|
|
3417
|
-
* @example Check whether a specific schema is needed
|
|
3418
|
-
* ```ts
|
|
3419
|
-
* const allowed = collectUsedSchemaNames(includedOps, inputNode.schemas)
|
|
3420
|
-
* allowed.has('OrderStatus') // false when no included operation references OrderStatus
|
|
3421
|
-
* ```
|
|
3422
|
-
*/
|
|
3423
3446
|
declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
3424
3447
|
/**
|
|
3425
3448
|
* Identifies all schemas that participate in circular dependency chains, including direct self-loops.
|
|
@@ -3447,5 +3470,5 @@ declare function containsCircularRef(node: SchemaNode | undefined, {
|
|
|
3447
3470
|
excludeName?: string;
|
|
3448
3471
|
}): boolean;
|
|
3449
3472
|
//#endregion
|
|
3450
|
-
export { type ArraySchemaNode, type ArrowFunctionNode, AsyncVisitor, type BaseNode, type BreakNode, type CodeNode, CollectOptions, CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpStatusCode, type ImportNode, InferSchema, InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, OperationParamsResolver, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, ParentOf, ParserOptions, type PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, type PropertyNode, RefMap, type RefSchemaNode, type ResponseNode, ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, UserFileNode, Visitor, VisitorContext, VisitorDepth, WalkOptions, caseParams, childName, collect, collectImports, collectReferencedSchemaNames, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createText, createType, definePrinter, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isInputNode, isOperationNode, isOutputNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
3473
|
+
export { type ArraySchemaNode, type ArrowFunctionNode, AsyncVisitor, type BaseNode, type BreakNode, type CodeNode, CollectOptions, CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpStatusCode, type ImportNode, InferSchema, InferSchemaNode, type InputMeta, type InputNode, type InputStreamNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, OperationParamsResolver, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, ParentOf, ParserOptions, type PrimitiveSchemaType, Printer, PrinterFactoryOptions, PrinterPartial, type PropertyNode, RefMap, type RefSchemaNode, type ResponseNode, ScalarPrimitive, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, UserFileNode, Visitor, VisitorContext, VisitorDepth, WalkOptions, caseParams, childName, collect, collectImports, collectLazy, collectReferencedSchemaNames, collectUsedSchemaNames, containsCircularRef, createArrowFunction, createBreak, createConst, createDiscriminantNode, createExport, createFile, createFunction, createFunctionParameter, createFunctionParameters, createImport, createInput, createJsx, createOperation, createOperationParams, createOutput, createParameter, createParameterGroup, createParamsType, createPrinterFactory, createProperty, createResponse, createSchema, createSource, createStreamInput, createText, createType, definePrinter, enumPropName, extractRefName, extractStringsFromNodes, findCircularSchemas, findDiscriminator, httpMethods, isInputNode, isOperationNode, isOutputNode, isScalarPrimitive, isSchemaNode, isStringType, mediaTypes, mergeAdjacentObjects, mergeAdjacentObjectsLazy, narrowSchema, nodeKinds, resolveRefName, schemaTypes, setDiscriminatorEnum, setEnumName, simplifyUnion, syncOptionality, syncSchemaRef, transform, walk };
|
|
3451
3474
|
//# sourceMappingURL=index.d.ts.map
|