@kubb/ast 5.0.0-beta.20 → 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/dist/index.cjs +18 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -30
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/guards.ts +3 -3
- package/src/nodes/operation.ts +1 -1
- package/src/nodes/response.ts +1 -1
- package/src/nodes/root.ts +1 -1
- package/src/nodes/schema.ts +5 -3
- package/src/printer.ts +15 -16
- package/src/refs.ts +4 -2
- package/src/resolvers.ts +4 -4
- package/src/transformers.ts +1 -1
- package/src/utils.ts +13 -13
- package/src/visitor.ts +10 -10
package/dist/index.d.ts
CHANGED
|
@@ -1326,8 +1326,9 @@ type RefSchemaNode = SchemaNodeBase & {
|
|
|
1326
1326
|
type: 'ref';
|
|
1327
1327
|
/**
|
|
1328
1328
|
* Referenced schema name.
|
|
1329
|
+
* `null` means Kubb has processed this and determined there is no applicable name.
|
|
1329
1330
|
*/
|
|
1330
|
-
name?: string;
|
|
1331
|
+
name?: string | null;
|
|
1331
1332
|
/**
|
|
1332
1333
|
* Original `$ref` path, for example, `#/components/schemas/Order`.
|
|
1333
1334
|
* Used to resolve names later.
|
|
@@ -1340,12 +1341,13 @@ type RefSchemaNode = SchemaNodeBase & {
|
|
|
1340
1341
|
/**
|
|
1341
1342
|
* The fully-parsed schema that this ref resolves to.
|
|
1342
1343
|
* Populated during OAS parsing when the referenced definition can be resolved.
|
|
1343
|
-
* `
|
|
1344
|
+
* `null` when the ref cannot be resolved or is part of a circular chain.
|
|
1345
|
+
* `undefined` when resolution has not been attempted.
|
|
1344
1346
|
*
|
|
1345
1347
|
* Useful for inspecting the referenced schema's structure (e.g. `primitive`, `properties`)
|
|
1346
1348
|
* without following the reference manually.
|
|
1347
1349
|
*/
|
|
1348
|
-
schema?: SchemaNode;
|
|
1350
|
+
schema?: SchemaNode | null;
|
|
1349
1351
|
};
|
|
1350
1352
|
/**
|
|
1351
1353
|
* Datetime schema.
|
|
@@ -1693,7 +1695,7 @@ type ResponseNode = BaseNode & {
|
|
|
1693
1695
|
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
1694
1696
|
* Set when a referenced schema has `writeOnly` fields that should not appear in response types.
|
|
1695
1697
|
*/
|
|
1696
|
-
keysToOmit?: Array<string
|
|
1698
|
+
keysToOmit?: Array<string> | null;
|
|
1697
1699
|
};
|
|
1698
1700
|
//#endregion
|
|
1699
1701
|
//#region src/nodes/operation.d.ts
|
|
@@ -1794,7 +1796,7 @@ type OperationNode = BaseNode & {
|
|
|
1794
1796
|
* Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
|
|
1795
1797
|
* Set when a referenced schema has `readOnly` fields that should be omitted in request types.
|
|
1796
1798
|
*/
|
|
1797
|
-
keysToOmit?: Array<string
|
|
1799
|
+
keysToOmit?: Array<string> | null;
|
|
1798
1800
|
}>;
|
|
1799
1801
|
};
|
|
1800
1802
|
/**
|
|
@@ -1857,7 +1859,7 @@ type InputMeta = {
|
|
|
1857
1859
|
/**
|
|
1858
1860
|
* Resolved base URL from the first matching server entry in the source document.
|
|
1859
1861
|
*/
|
|
1860
|
-
baseURL?: string;
|
|
1862
|
+
baseURL?: string | null;
|
|
1861
1863
|
/**
|
|
1862
1864
|
* Names of schemas that participate in a circular reference chain.
|
|
1863
1865
|
* Computed once during the adapter pre-scan — use this instead of calling
|
|
@@ -2657,10 +2659,10 @@ declare function createJsx(value: string): JsxNode;
|
|
|
2657
2659
|
* @example
|
|
2658
2660
|
* ```ts
|
|
2659
2661
|
* const schema = createSchema({ type: 'string' })
|
|
2660
|
-
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode |
|
|
2662
|
+
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
|
|
2661
2663
|
* ```
|
|
2662
2664
|
*/
|
|
2663
|
-
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;
|
|
2664
2666
|
/**
|
|
2665
2667
|
* Returns `true` when the input is an `InputNode`.
|
|
2666
2668
|
*
|
|
@@ -2725,7 +2727,7 @@ type PrinterHandlerContext<TOutput, TOptions extends object> = {
|
|
|
2725
2727
|
* Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.
|
|
2726
2728
|
* Use `this.transform` inside `nodes` handlers and inside the `print` override.
|
|
2727
2729
|
*/
|
|
2728
|
-
transform: (node: SchemaNode) => TOutput | null
|
|
2730
|
+
transform: (node: SchemaNode) => TOutput | null;
|
|
2729
2731
|
/**
|
|
2730
2732
|
* Options for this printer instance.
|
|
2731
2733
|
*/
|
|
@@ -2743,7 +2745,7 @@ type PrinterHandlerContext<TOutput, TOptions extends object> = {
|
|
|
2743
2745
|
* }
|
|
2744
2746
|
* ```
|
|
2745
2747
|
*/
|
|
2746
|
-
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;
|
|
2747
2749
|
/**
|
|
2748
2750
|
* Partial map of per-node-type handler overrides for a printer.
|
|
2749
2751
|
*
|
|
@@ -2806,13 +2808,13 @@ type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
|
|
|
2806
2808
|
* Always dispatches through the `nodes` map; never calls the `print` override.
|
|
2807
2809
|
* Use this when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
|
|
2808
2810
|
*/
|
|
2809
|
-
transform: (node: SchemaNode) => T['output'] | null
|
|
2811
|
+
transform: (node: SchemaNode) => T['output'] | null;
|
|
2810
2812
|
/**
|
|
2811
2813
|
* Public printer. If the builder provides a root-level `print`, this calls that
|
|
2812
2814
|
* higher-level function (which may produce full declarations).
|
|
2813
2815
|
* Otherwise, falls back to the node-level dispatcher.
|
|
2814
2816
|
*/
|
|
2815
|
-
print: (node: SchemaNode) => T['printOutput'] | null
|
|
2817
|
+
print: (node: SchemaNode) => T['printOutput'] | null;
|
|
2816
2818
|
};
|
|
2817
2819
|
/**
|
|
2818
2820
|
* Builder function passed to `definePrinter`.
|
|
@@ -2885,22 +2887,22 @@ declare function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryO
|
|
|
2885
2887
|
* )
|
|
2886
2888
|
* ```
|
|
2887
2889
|
*/
|
|
2888
|
-
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"]) => {
|
|
2889
2891
|
name: T["name"];
|
|
2890
2892
|
options: T["options"];
|
|
2891
2893
|
nodes: Partial<{ [K in TKey]: (this: {
|
|
2892
|
-
transform: (node: TNode) => T["output"] | null
|
|
2894
|
+
transform: (node: TNode) => T["output"] | null;
|
|
2893
2895
|
options: T["options"];
|
|
2894
|
-
}, node: TNodeByKey[K]) => T["output"] | null
|
|
2896
|
+
}, node: TNodeByKey[K]) => T["output"] | null }>;
|
|
2895
2897
|
print?: (this: {
|
|
2896
|
-
transform: (node: TNode) => T["output"] | null
|
|
2898
|
+
transform: (node: TNode) => T["output"] | null;
|
|
2897
2899
|
options: T["options"];
|
|
2898
|
-
}, node: TNode) => T["printOutput"] | null
|
|
2900
|
+
}, node: TNode) => T["printOutput"] | null;
|
|
2899
2901
|
}) => (options?: T["options"]) => {
|
|
2900
2902
|
name: T["name"];
|
|
2901
2903
|
options: T["options"];
|
|
2902
|
-
transform: (node: TNode) => T["output"] | null
|
|
2903
|
-
print: (node: TNode) => T["printOutput"] | null
|
|
2904
|
+
transform: (node: TNode) => T["output"] | null;
|
|
2905
|
+
print: (node: TNode) => T["printOutput"] | null;
|
|
2904
2906
|
};
|
|
2905
2907
|
//#endregion
|
|
2906
2908
|
//#region src/refs.d.ts
|
|
@@ -2934,7 +2936,7 @@ declare function collectImports<TImport>({
|
|
|
2934
2936
|
}: {
|
|
2935
2937
|
node: SchemaNode;
|
|
2936
2938
|
nameMapping: Map<string, string>;
|
|
2937
|
-
resolve: (schemaName: string) => TImport |
|
|
2939
|
+
resolve: (schemaName: string) => TImport | null;
|
|
2938
2940
|
}): Array<TImport>;
|
|
2939
2941
|
//#endregion
|
|
2940
2942
|
//#region src/transformers.d.ts
|
|
@@ -3103,13 +3105,13 @@ type AsyncVisitor = {
|
|
|
3103
3105
|
* ```
|
|
3104
3106
|
*/
|
|
3105
3107
|
type CollectVisitor<T> = {
|
|
3106
|
-
input?(node: InputNode, context: VisitorContext<InputNode>): T | undefined;
|
|
3107
|
-
output?(node: OutputNode, context: VisitorContext<OutputNode>): T | undefined;
|
|
3108
|
-
operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | undefined;
|
|
3109
|
-
schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | undefined;
|
|
3110
|
-
property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | undefined;
|
|
3111
|
-
parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | undefined;
|
|
3112
|
-
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;
|
|
3113
3115
|
};
|
|
3114
3116
|
/**
|
|
3115
3117
|
* Options for `transform`.
|
|
@@ -3228,7 +3230,7 @@ declare function transform(node: Node, options: TransformOptions): Node;
|
|
|
3228
3230
|
/**
|
|
3229
3231
|
* Runs a depth-first synchronous collection pass.
|
|
3230
3232
|
*
|
|
3231
|
-
* Non-`
|
|
3233
|
+
* Non-`null` values returned by visitor callbacks are appended to the result.
|
|
3232
3234
|
*
|
|
3233
3235
|
* @example
|
|
3234
3236
|
* ```ts
|
|
@@ -3430,7 +3432,7 @@ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): st
|
|
|
3430
3432
|
/**
|
|
3431
3433
|
* Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
|
|
3432
3434
|
*
|
|
3433
|
-
* Returns `
|
|
3435
|
+
* Returns `null` for non-ref nodes or when no name can be resolved. Use this to get a schema's
|
|
3434
3436
|
* identifier for type definitions or error messages.
|
|
3435
3437
|
*
|
|
3436
3438
|
* @example
|
|
@@ -3439,7 +3441,7 @@ declare function extractStringsFromNodes(nodes: Array<CodeNode> | undefined): st
|
|
|
3439
3441
|
* // => 'Pet'
|
|
3440
3442
|
* ```
|
|
3441
3443
|
*/
|
|
3442
|
-
declare function resolveRefName(node: SchemaNode | undefined): string |
|
|
3444
|
+
declare function resolveRefName(node: SchemaNode | undefined): string | null;
|
|
3443
3445
|
declare function collectReferencedSchemaNames(node: SchemaNode | undefined, out?: Set<string>): Set<string>;
|
|
3444
3446
|
declare function collectUsedSchemaNames(operations: ReadonlyArray<OperationNode>, schemas: ReadonlyArray<SchemaNode>): Set<string>;
|
|
3445
3447
|
/**
|
package/dist/index.js
CHANGED
|
@@ -432,11 +432,11 @@ function trimExtName(text) {
|
|
|
432
432
|
* @example
|
|
433
433
|
* ```ts
|
|
434
434
|
* const schema = createSchema({ type: 'string' })
|
|
435
|
-
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode |
|
|
435
|
+
* const stringNode = narrowSchema(schema, 'string') // StringSchemaNode | null
|
|
436
436
|
* ```
|
|
437
437
|
*/
|
|
438
438
|
function narrowSchema(node, type) {
|
|
439
|
-
return node?.type === type ? node :
|
|
439
|
+
return node?.type === type ? node : null;
|
|
440
440
|
}
|
|
441
441
|
function isKind(kind) {
|
|
442
442
|
return (node) => node.kind === kind;
|
|
@@ -727,7 +727,7 @@ function transform(node, options) {
|
|
|
727
727
|
/**
|
|
728
728
|
* Runs a depth-first synchronous collection pass.
|
|
729
729
|
*
|
|
730
|
-
* Non-`
|
|
730
|
+
* Non-`null` values returned by visitor callbacks are appended to the result.
|
|
731
731
|
*
|
|
732
732
|
* @example
|
|
733
733
|
* ```ts
|
|
@@ -771,7 +771,7 @@ function* collectLazy(node, options) {
|
|
|
771
771
|
v = visitor.response?.(node, { parent });
|
|
772
772
|
break;
|
|
773
773
|
}
|
|
774
|
-
if (v
|
|
774
|
+
if (v != null) yield v;
|
|
775
775
|
for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
|
|
776
776
|
...options,
|
|
777
777
|
parent: node
|
|
@@ -970,7 +970,7 @@ function createOperationParams(node, options) {
|
|
|
970
970
|
}));
|
|
971
971
|
} else {
|
|
972
972
|
if (pathParams.length) if (pathParamsType === "inlineSpread") {
|
|
973
|
-
const spreadType = resolver?.resolvePathParamsName(node, pathParams[0])
|
|
973
|
+
const spreadType = resolver?.resolvePathParamsName(node, pathParams[0]);
|
|
974
974
|
params.push(createFunctionParameter({
|
|
975
975
|
name: pathName,
|
|
976
976
|
type: spreadType ? wrapType(spreadType) : void 0,
|
|
@@ -1046,13 +1046,13 @@ function buildGroupParam({ name, node, params, groupType, resolver, wrapType })
|
|
|
1046
1046
|
}
|
|
1047
1047
|
/**
|
|
1048
1048
|
* Derives a {@link ParamGroupType} from the resolver's group method.
|
|
1049
|
-
* Returns `
|
|
1049
|
+
* Returns `null` when the group name equals the individual param name (no real group).
|
|
1050
1050
|
*/
|
|
1051
1051
|
function resolveGroupType({ node, params, groupMethod, resolver }) {
|
|
1052
|
-
if (!params.length) return;
|
|
1052
|
+
if (!params.length) return null;
|
|
1053
1053
|
const firstParam = params[0];
|
|
1054
1054
|
const groupName = groupMethod.call(resolver, node, firstParam);
|
|
1055
|
-
if (groupName === resolver.resolveParamName(node, firstParam)) return;
|
|
1055
|
+
if (groupName === resolver.resolveParamName(node, firstParam)) return null;
|
|
1056
1056
|
const allOptional = params.every((p) => !p.required);
|
|
1057
1057
|
return {
|
|
1058
1058
|
type: createParamsType({
|
|
@@ -1245,7 +1245,7 @@ function extractStringsFromNodes(nodes) {
|
|
|
1245
1245
|
/**
|
|
1246
1246
|
* Resolves the schema name of a ref node, falling back through `ref` → `name` → nested `schema.name`.
|
|
1247
1247
|
*
|
|
1248
|
-
* Returns `
|
|
1248
|
+
* Returns `null` for non-ref nodes or when no name can be resolved. Use this to get a schema's
|
|
1249
1249
|
* identifier for type definitions or error messages.
|
|
1250
1250
|
*
|
|
1251
1251
|
* @example
|
|
@@ -1255,9 +1255,9 @@ function extractStringsFromNodes(nodes) {
|
|
|
1255
1255
|
* ```
|
|
1256
1256
|
*/
|
|
1257
1257
|
function resolveRefName(node) {
|
|
1258
|
-
if (!node || node.type !== "ref") return
|
|
1259
|
-
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ??
|
|
1260
|
-
return node.name ?? node.schema?.name ??
|
|
1258
|
+
if (!node || node.type !== "ref") return null;
|
|
1259
|
+
if (node.ref) return extractRefName(node.ref) ?? node.name ?? node.schema?.name ?? null;
|
|
1260
|
+
return node.name ?? node.schema?.name ?? null;
|
|
1261
1261
|
}
|
|
1262
1262
|
/**
|
|
1263
1263
|
* Collects every named schema referenced (transitively) from a node via ref edges.
|
|
@@ -1393,9 +1393,9 @@ function findCircularSchemas(schemas) {
|
|
|
1393
1393
|
function containsCircularRef(node, { circularSchemas, excludeName }) {
|
|
1394
1394
|
if (!node || circularSchemas.size === 0) return false;
|
|
1395
1395
|
for (const _ of collectLazy(node, { schema(child) {
|
|
1396
|
-
if (child.type !== "ref") return
|
|
1396
|
+
if (child.type !== "ref") return null;
|
|
1397
1397
|
const name = resolveRefName(child);
|
|
1398
|
-
return name && name !== excludeName && circularSchemas.has(name) ? true :
|
|
1398
|
+
return name && name !== excludeName && circularSchemas.has(name) ? true : null;
|
|
1399
1399
|
} })) return true;
|
|
1400
1400
|
return false;
|
|
1401
1401
|
}
|
|
@@ -2097,7 +2097,7 @@ function createPrinterFactory(getKey) {
|
|
|
2097
2097
|
options: resolvedOptions,
|
|
2098
2098
|
transform: (node) => {
|
|
2099
2099
|
const key = getKey(node);
|
|
2100
|
-
if (key ===
|
|
2100
|
+
if (key === null) return null;
|
|
2101
2101
|
const handler = nodes[key];
|
|
2102
2102
|
if (!handler) return null;
|
|
2103
2103
|
return handler.call(context, node);
|
|
@@ -2134,10 +2134,10 @@ function enumPropName(parentName, propName, enumSuffix) {
|
|
|
2134
2134
|
function collectImports({ node, nameMapping, resolve }) {
|
|
2135
2135
|
return collect(node, { schema(schemaNode) {
|
|
2136
2136
|
const schemaRef = narrowSchema(schemaNode, "ref");
|
|
2137
|
-
if (!schemaRef?.ref) return;
|
|
2137
|
+
if (!schemaRef?.ref) return null;
|
|
2138
2138
|
const rawName = extractRefName(schemaRef.ref);
|
|
2139
2139
|
const result = resolve(nameMapping.get(rawName) ?? rawName);
|
|
2140
|
-
if (!result) return;
|
|
2140
|
+
if (!result) return null;
|
|
2141
2141
|
return result;
|
|
2142
2142
|
} });
|
|
2143
2143
|
}
|
|
@@ -2243,7 +2243,7 @@ function setEnumName(propNode, parentName, propName, enumSuffix) {
|
|
|
2243
2243
|
const enumNode = narrowSchema(propNode, "enum");
|
|
2244
2244
|
if (enumNode?.primitive === "boolean") return {
|
|
2245
2245
|
...propNode,
|
|
2246
|
-
name:
|
|
2246
|
+
name: null
|
|
2247
2247
|
};
|
|
2248
2248
|
if (enumNode) return {
|
|
2249
2249
|
...propNode,
|