@kubb/adapter-oas 5.18.4 → 5.18.6
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 +91 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +92 -71
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineExtension } from "@kubb/core";
|
|
2
|
-
import { Diagnostics, ast, childName, enumPrimitive, enumPropName,
|
|
2
|
+
import { Diagnostics, ast, childName, enumPrimitive, enumPropName, macroDedupeUnion, macroDiscriminatorEnum, macroEnumName, mergeAdjacentObjectsLazy } from "@kubb/kit";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { access, readFile } from "node:fs/promises";
|
|
@@ -20,7 +20,7 @@ var compatibility = {
|
|
|
20
20
|
"node": ">=22.22"
|
|
21
21
|
};
|
|
22
22
|
// package.json
|
|
23
|
-
var version = "5.18.
|
|
23
|
+
var version = "5.18.6";
|
|
24
24
|
// src/constants.ts
|
|
25
25
|
/**
|
|
26
26
|
* Default parser options applied when no explicit options are provided.
|
|
@@ -60,17 +60,6 @@ const SUPPORTED_METHODS = /* @__PURE__ */ new Set([
|
|
|
60
60
|
"query"
|
|
61
61
|
]);
|
|
62
62
|
/**
|
|
63
|
-
* Media types OpenAPI 3.2 reads as a stream of items (its "sequential media types"), each described by `itemSchema`.
|
|
64
|
-
*/
|
|
65
|
-
const STREAM_MEDIA_TYPES = /* @__PURE__ */ new Set([
|
|
66
|
-
"application/jsonl",
|
|
67
|
-
"application/x-ndjson",
|
|
68
|
-
"application/json-seq",
|
|
69
|
-
"application/geo+json-seq",
|
|
70
|
-
"text/event-stream",
|
|
71
|
-
"multipart/mixed"
|
|
72
|
-
]);
|
|
73
|
-
/**
|
|
74
63
|
* Set of JSON Schema keywords that prevent a schema fragment from being inlined during `allOf` flattening.
|
|
75
64
|
*
|
|
76
65
|
* A fragment that contains any of these keys carries structural meaning of its own and must stay as a separate
|
|
@@ -167,21 +156,21 @@ const enumDescriptionKeys = ["x-enumDescriptions", "x-enum-descriptions"];
|
|
|
167
156
|
function buildDiscriminatorChildMap(schemas) {
|
|
168
157
|
const childMap = /* @__PURE__ */ new Map();
|
|
169
158
|
for (const schema of schemas) {
|
|
170
|
-
const unionNode = ast.
|
|
159
|
+
const unionNode = ast.schema.narrow(schema, "union") ?? ast.schema.narrow(schema, "intersection")?.members?.map((member) => ast.schema.narrow(member, "union")).find((union) => union);
|
|
171
160
|
if (!unionNode?.discriminatorPropertyName || !unionNode.members) continue;
|
|
172
161
|
const { discriminatorPropertyName, members } = unionNode;
|
|
173
162
|
for (const member of members) {
|
|
174
|
-
const intersectionNode = ast.
|
|
163
|
+
const intersectionNode = ast.schema.narrow(member, "intersection");
|
|
175
164
|
if (!intersectionNode?.members) continue;
|
|
176
165
|
let refNode = null;
|
|
177
166
|
let objNode = null;
|
|
178
167
|
for (const m of intersectionNode.members) {
|
|
179
|
-
refNode ??= ast.
|
|
180
|
-
objNode ??= ast.
|
|
168
|
+
refNode ??= ast.schema.narrow(m, "ref");
|
|
169
|
+
objNode ??= ast.schema.narrow(m, "object");
|
|
181
170
|
}
|
|
182
171
|
if (!refNode?.name || !objNode) continue;
|
|
183
172
|
const prop = objNode.properties.find((p) => p.name === discriminatorPropertyName);
|
|
184
|
-
const enumNode = prop ? ast.
|
|
173
|
+
const enumNode = prop ? ast.schema.narrow(prop.schema, "enum") : null;
|
|
185
174
|
if (!enumNode?.enumValues?.length) continue;
|
|
186
175
|
const enumValues = enumNode.enumValues.filter((v) => v !== null);
|
|
187
176
|
if (!enumValues.length) continue;
|
|
@@ -216,7 +205,7 @@ function patchDiscriminatorNode(node, entry) {
|
|
|
216
205
|
required: true,
|
|
217
206
|
schema: enumSchema
|
|
218
207
|
});
|
|
219
|
-
const objectNode = ast.
|
|
208
|
+
const objectNode = ast.schema.narrow(node, "object");
|
|
220
209
|
if (objectNode) {
|
|
221
210
|
const existingIdx = objectNode.properties.findIndex((p) => p.name === propertyName);
|
|
222
211
|
const newProperties = existingIdx >= 0 ? objectNode.properties.map((p, i) => i === existingIdx ? newProp : p) : [...objectNode.properties, newProp];
|
|
@@ -225,14 +214,14 @@ function patchDiscriminatorNode(node, entry) {
|
|
|
225
214
|
properties: newProperties
|
|
226
215
|
};
|
|
227
216
|
}
|
|
228
|
-
const intersectionNode = ast.
|
|
217
|
+
const intersectionNode = ast.schema.narrow(node, "intersection");
|
|
229
218
|
if (!intersectionNode?.members) return node;
|
|
230
219
|
const discriminantNode = ast.factory.createSchema({
|
|
231
220
|
type: "object",
|
|
232
221
|
primitive: "object",
|
|
233
222
|
properties: [newProp]
|
|
234
223
|
});
|
|
235
|
-
const patchedIdx = intersectionNode.members.findIndex((member) => ast.
|
|
224
|
+
const patchedIdx = intersectionNode.members.findIndex((member) => ast.schema.narrow(member, "object")?.properties.some((p) => p.name === propertyName));
|
|
236
225
|
const newMembers = patchedIdx >= 0 ? intersectionNode.members.map((member, i) => i === patchedIdx ? patchDiscriminatorNode(member, entry) : member) : [...intersectionNode.members, discriminantNode];
|
|
237
226
|
return {
|
|
238
227
|
...intersectionNode,
|
|
@@ -1455,22 +1444,16 @@ function toInputTags(tags) {
|
|
|
1455
1444
|
}
|
|
1456
1445
|
// src/model/mediaType.ts
|
|
1457
1446
|
/**
|
|
1458
|
-
*
|
|
1459
|
-
*/
|
|
1460
|
-
function baseMediaType(contentType) {
|
|
1461
|
-
return contentType.split(";")[0].trim().toLowerCase();
|
|
1462
|
-
}
|
|
1463
|
-
/**
|
|
1464
|
-
* Returns `true` for a media type read as a stream of items: one that OpenAPI 3.2 lists, or any that declares `itemSchema`.
|
|
1447
|
+
* Returns `true` for a media type read as a stream of items: one `ast.mediaType.isStream` accepts, or any that declares `itemSchema`.
|
|
1465
1448
|
*/
|
|
1466
1449
|
function isStream(contentType, mediaType) {
|
|
1467
|
-
return
|
|
1450
|
+
return ast.mediaType.isStream(contentType) || mediaType?.itemSchema !== void 0;
|
|
1468
1451
|
}
|
|
1469
1452
|
/**
|
|
1470
1453
|
* Whether the media type is `text/event-stream`, with or without parameters.
|
|
1471
1454
|
*/
|
|
1472
1455
|
function isEventStream(contentType) {
|
|
1473
|
-
return
|
|
1456
|
+
return ast.mediaType.getBase(contentType) === "text/event-stream";
|
|
1474
1457
|
}
|
|
1475
1458
|
/**
|
|
1476
1459
|
* Replaces a `data` string that holds JSON with its `contentSchema`, so the event reads as parsed.
|
|
@@ -1547,8 +1530,29 @@ function toEventSchema(schema, refs) {
|
|
|
1547
1530
|
[key]: members.map((member) => isReference(member) ? withParsedRef(member, refs) : withParsedData(merge ? mergeSchemas(shared, member) : member, refs))
|
|
1548
1531
|
};
|
|
1549
1532
|
}
|
|
1533
|
+
const SSE_FIELDS = /* @__PURE__ */ new Set([
|
|
1534
|
+
"event",
|
|
1535
|
+
"id",
|
|
1536
|
+
"retry",
|
|
1537
|
+
"data"
|
|
1538
|
+
]);
|
|
1550
1539
|
/**
|
|
1551
|
-
*
|
|
1540
|
+
* Property names of the schema and its `allOf` members, following `$ref`s, as one combined object declares them.
|
|
1541
|
+
*/
|
|
1542
|
+
function collectFields(schema, refs, seen) {
|
|
1543
|
+
if (isReference(schema)) {
|
|
1544
|
+
if (seen.has(schema.$ref)) return [];
|
|
1545
|
+
seen.add(schema.$ref);
|
|
1546
|
+
const resolved = refs.resolve(schema.$ref, { report: false });
|
|
1547
|
+
return resolved ? collectFields(resolved, refs, seen) : [];
|
|
1548
|
+
}
|
|
1549
|
+
const members = schema.allOf ?? [];
|
|
1550
|
+
return [...Object.keys(schema.properties ?? {}), ...members.flatMap((member) => collectFields(member, refs, seen))];
|
|
1551
|
+
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Whether the schema, following `$ref`s, or a `oneOf`/`anyOf` member of it is a whole Server-Sent Event: its combined
|
|
1554
|
+
* `allOf` fields declare `data`, or `event` with no field an event cannot carry. An `event` next to fields such as
|
|
1555
|
+
* `planet` is the payload's own property, sent as JSON in the `data:` line.
|
|
1552
1556
|
*/
|
|
1553
1557
|
function declaresEventFields(schema, refs, seen) {
|
|
1554
1558
|
if (isReference(schema)) {
|
|
@@ -1557,15 +1561,13 @@ function declaresEventFields(schema, refs, seen) {
|
|
|
1557
1561
|
const resolved = refs.resolve(schema.$ref, { report: false });
|
|
1558
1562
|
return !!resolved && declaresEventFields(resolved, refs, seen);
|
|
1559
1563
|
}
|
|
1560
|
-
|
|
1561
|
-
return
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
...schema.allOf ?? []
|
|
1565
|
-
].some((member) => declaresEventFields(member, refs, seen));
|
|
1564
|
+
const fields = collectFields(schema, refs, new Set(seen));
|
|
1565
|
+
if (fields.includes("data")) return true;
|
|
1566
|
+
if (fields.includes("event")) return fields.every((field) => SSE_FIELDS.has(field));
|
|
1567
|
+
return [...schema.oneOf ?? [], ...schema.anyOf ?? []].some((member) => declaresEventFields(member, refs, seen));
|
|
1566
1568
|
}
|
|
1567
1569
|
/**
|
|
1568
|
-
* Returns `'event'` when the item
|
|
1570
|
+
* Returns `'event'` when the item is a whole event, directly or in a composition member (see `declaresEventFields`), else `'data'`.
|
|
1569
1571
|
*/
|
|
1570
1572
|
function getItemShape(schema, refs) {
|
|
1571
1573
|
return declaresEventFields(schema, refs, /* @__PURE__ */ new Set()) ? "event" : "data";
|
|
@@ -1741,10 +1743,10 @@ function memberValues(node, propertyName, seen = /* @__PURE__ */ new Set()) {
|
|
|
1741
1743
|
seen.add(node);
|
|
1742
1744
|
const target = node.type === "ref" && node.schema ? node.schema : node;
|
|
1743
1745
|
if (target.type === "union") return [...new Set(target.members?.flatMap((member) => memberValues(member, propertyName, seen)))];
|
|
1744
|
-
return intersect(ast.
|
|
1746
|
+
return intersect(ast.schema.findProperties({
|
|
1745
1747
|
node,
|
|
1746
1748
|
propertyName
|
|
1747
|
-
}).map((property) => [...ast.
|
|
1749
|
+
}).map((property) => [...ast.schema.getLiterals(property.schema)]));
|
|
1748
1750
|
}
|
|
1749
1751
|
function intersect(slices) {
|
|
1750
1752
|
const pinned = slices.filter((values) => values.length > 0);
|
|
@@ -2012,6 +2014,25 @@ function parseParameter({ param, pointer, parentName, options, parseSchema, refs
|
|
|
2012
2014
|
...param.allowEmptyValue && { allowEmptyValue: true }
|
|
2013
2015
|
});
|
|
2014
2016
|
}
|
|
2017
|
+
function spreadQuerystring(param) {
|
|
2018
|
+
if (param.in !== "querystring") return [param];
|
|
2019
|
+
const schema = ast.ref.getSchema(param.schema);
|
|
2020
|
+
const formEncoded = !param.contentType || ast.mediaType.getBase(param.contentType) === "application/x-www-form-urlencoded";
|
|
2021
|
+
if (schema.type !== "object" || !formEncoded) return [param];
|
|
2022
|
+
return schema.properties.map((property) => {
|
|
2023
|
+
const { style, explode, allowReserved } = param.encoding?.[property.name] ?? {};
|
|
2024
|
+
return ast.factory.createParameter({
|
|
2025
|
+
...param.pointer ? { pointer: param.pointer } : {},
|
|
2026
|
+
name: property.name,
|
|
2027
|
+
in: "query",
|
|
2028
|
+
schema: property.schema,
|
|
2029
|
+
required: param.required && property.required,
|
|
2030
|
+
...style !== void 0 && { style },
|
|
2031
|
+
...explode !== void 0 && { explode },
|
|
2032
|
+
...allowReserved !== void 0 && { allowReserved }
|
|
2033
|
+
});
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2015
2036
|
/**
|
|
2016
2037
|
* Converts an OAS `Operation` into an `OperationNode`.
|
|
2017
2038
|
*/
|
|
@@ -2029,7 +2050,7 @@ function parseOperation({ operation, ...ctx }) {
|
|
|
2029
2050
|
refs,
|
|
2030
2051
|
...entry,
|
|
2031
2052
|
parentName: operationName
|
|
2032
|
-
}));
|
|
2053
|
+
})).flatMap(spreadQuerystring);
|
|
2033
2054
|
const body = getRequestBody({
|
|
2034
2055
|
operation,
|
|
2035
2056
|
refs
|
|
@@ -2049,7 +2070,7 @@ function parseOperation({ operation, ...ctx }) {
|
|
|
2049
2070
|
contentType: ct,
|
|
2050
2071
|
refs
|
|
2051
2072
|
});
|
|
2052
|
-
const node = ast.
|
|
2073
|
+
const node = ast.schema.applyOptionality(parseSchema({
|
|
2053
2074
|
schema,
|
|
2054
2075
|
name: requestBodyName
|
|
2055
2076
|
}), bodyRequired);
|
|
@@ -2342,7 +2363,7 @@ function isObjectLike(member, refs) {
|
|
|
2342
2363
|
*/
|
|
2343
2364
|
function narrowUnionMembers({ unionMembers, discriminator, sharedPropertiesNode, parentType, parse, name, refs }) {
|
|
2344
2365
|
function pickDiscriminatorPropertyNode(node, propertyName) {
|
|
2345
|
-
const discriminatorProperty = ast.
|
|
2366
|
+
const discriminatorProperty = ast.schema.narrow(node, "object")?.properties?.find((property) => property.name === propertyName);
|
|
2346
2367
|
if (!discriminatorProperty) return null;
|
|
2347
2368
|
return ast.factory.createSchema({
|
|
2348
2369
|
type: "object",
|
|
@@ -2352,7 +2373,7 @@ function narrowUnionMembers({ unionMembers, discriminator, sharedPropertiesNode,
|
|
|
2352
2373
|
}
|
|
2353
2374
|
function implicitDiscriminantValue(member) {
|
|
2354
2375
|
if (!discriminator || discriminator.mapping || !isReference(member)) return null;
|
|
2355
|
-
const value =
|
|
2376
|
+
const value = ast.ref.getName(member.$ref);
|
|
2356
2377
|
if (!value) return null;
|
|
2357
2378
|
const variant = refs.resolve(member.$ref, { report: false });
|
|
2358
2379
|
if (!variant) return null;
|
|
@@ -2400,7 +2421,7 @@ function narrowUnionMembers({ unionMembers, discriminator, sharedPropertiesNode,
|
|
|
2400
2421
|
name
|
|
2401
2422
|
});
|
|
2402
2423
|
if (!discriminatorValues.length || !discriminator || !isObjectLike(s, refs)) return memberNode;
|
|
2403
|
-
const narrowedDiscriminatorNode = sharedPropertiesNode ? pickDiscriminatorPropertyNode(ast.
|
|
2424
|
+
const narrowedDiscriminatorNode = sharedPropertiesNode ? pickDiscriminatorPropertyNode(ast.macro.apply(sharedPropertiesNode, [macroDiscriminatorEnum({
|
|
2404
2425
|
propertyName: discriminator.propertyName,
|
|
2405
2426
|
values: discriminatorValues
|
|
2406
2427
|
})], { depth: "shallow" }), discriminator.propertyName) : void 0;
|
|
@@ -2592,7 +2613,7 @@ function resolveUnionSchema(schema, siblingProperties) {
|
|
|
2592
2613
|
*
|
|
2593
2614
|
* The resolved schema is stored in `node.schema`. Usage-site sibling fields
|
|
2594
2615
|
* (description, readOnly, nullable, etc.) are stored directly on the ref node.
|
|
2595
|
-
* Use `
|
|
2616
|
+
* Use `ast.ref.mergeSchema(node)` in printers to get a merged view of both.
|
|
2596
2617
|
* Circular refs are detected in `refs.resolveNode` and leave `schema` as `null`.
|
|
2597
2618
|
*/
|
|
2598
2619
|
function convertRef({ schema, name, nullable, defaultValue, document, parse, refs, renames }) {
|
|
@@ -2604,7 +2625,7 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
|
|
|
2604
2625
|
nullable,
|
|
2605
2626
|
defaultValue
|
|
2606
2627
|
};
|
|
2607
|
-
if (refPath && document.components && !refs.resolve(refPath, { report: false })) return createNode(ctx, { type: ast.
|
|
2628
|
+
if (refPath && document.components && !refs.resolve(refPath, { report: false })) return createNode(ctx, { type: ast.schema.types.unknown });
|
|
2608
2629
|
if (refPath && !refPath.startsWith("#/components/schemas/") && resolvedSchema) return ast.factory.createSchema({
|
|
2609
2630
|
...resolvedSchema,
|
|
2610
2631
|
title: schema.title ?? resolvedSchema.title,
|
|
@@ -2618,8 +2639,8 @@ function convertRef({ schema, name, nullable, defaultValue, document, parse, ref
|
|
|
2618
2639
|
});
|
|
2619
2640
|
const targetName = renames?.get(schema.$ref);
|
|
2620
2641
|
return createNode(ctx, {
|
|
2621
|
-
type: ast.
|
|
2622
|
-
name:
|
|
2642
|
+
type: ast.schema.types.ref,
|
|
2643
|
+
name: ast.ref.getName(schema.$ref),
|
|
2623
2644
|
ref: schema.$ref,
|
|
2624
2645
|
...targetName ? { targetName } : {},
|
|
2625
2646
|
schema: resolvedSchema
|
|
@@ -2630,7 +2651,7 @@ function convertNot({ schema, name, nullable, defaultValue, parse }) {
|
|
|
2630
2651
|
const { not, ...rest } = schema;
|
|
2631
2652
|
const [subschema] = resolveUnionMembers([not], rest.properties ?? {});
|
|
2632
2653
|
const notNode = ast.factory.createSchema({
|
|
2633
|
-
type: ast.
|
|
2654
|
+
type: ast.schema.types.not,
|
|
2634
2655
|
members: [parse({ schema: subschema })]
|
|
2635
2656
|
});
|
|
2636
2657
|
return createNode({
|
|
@@ -2639,7 +2660,7 @@ function convertNot({ schema, name, nullable, defaultValue, parse }) {
|
|
|
2639
2660
|
nullable,
|
|
2640
2661
|
defaultValue
|
|
2641
2662
|
}, {
|
|
2642
|
-
type: ast.
|
|
2663
|
+
type: ast.schema.types.intersection,
|
|
2643
2664
|
members: [parse({
|
|
2644
2665
|
schema: rest,
|
|
2645
2666
|
name
|
|
@@ -2767,7 +2788,7 @@ function convertAllOf({ schema: original, name, nullable, defaultValue, parse, r
|
|
|
2767
2788
|
nullable,
|
|
2768
2789
|
defaultValue
|
|
2769
2790
|
}, {
|
|
2770
|
-
type: ast.
|
|
2791
|
+
type: ast.schema.types.intersection,
|
|
2771
2792
|
members: [...mergeAdjacentObjectsLazy(allOfMembers.slice(0, syntheticStart)), ...mergeAdjacentObjectsLazy(allOfMembers.slice(syntheticStart))]
|
|
2772
2793
|
});
|
|
2773
2794
|
}
|
|
@@ -2811,24 +2832,24 @@ function convertUnion(context) {
|
|
|
2811
2832
|
refs
|
|
2812
2833
|
});
|
|
2813
2834
|
const unionNode = createNode(ctx, {
|
|
2814
|
-
type: ast.
|
|
2835
|
+
type: ast.schema.types.union,
|
|
2815
2836
|
strategy,
|
|
2816
2837
|
members,
|
|
2817
|
-
discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.
|
|
2838
|
+
discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.schema.inferDiscriminator(members)
|
|
2818
2839
|
});
|
|
2819
2840
|
const requiredProperties = missingRequired.map((name) => ast.factory.createProperty({
|
|
2820
2841
|
name,
|
|
2821
2842
|
required: true,
|
|
2822
|
-
schema: ast.factory.createSchema({ type: ast.
|
|
2843
|
+
schema: ast.factory.createSchema({ type: ast.schema.types.unknown })
|
|
2823
2844
|
}));
|
|
2824
2845
|
const siblings = sharedPropertiesNode ? [sharedPropertiesNode] : [];
|
|
2825
2846
|
if (requiredProperties.length) siblings.push(ast.factory.createSchema({
|
|
2826
|
-
type: ast.
|
|
2847
|
+
type: ast.schema.types.object,
|
|
2827
2848
|
properties: requiredProperties
|
|
2828
2849
|
}));
|
|
2829
2850
|
if (!siblings.length) return unionNode;
|
|
2830
2851
|
return createNode(ctx, {
|
|
2831
|
-
type: ast.
|
|
2852
|
+
type: ast.schema.types.intersection,
|
|
2832
2853
|
members: [unionNode, ...siblings]
|
|
2833
2854
|
});
|
|
2834
2855
|
}
|
|
@@ -2837,12 +2858,12 @@ function convertUnion(context) {
|
|
|
2837
2858
|
name
|
|
2838
2859
|
}));
|
|
2839
2860
|
const unionNode = createNode(ctx, {
|
|
2840
|
-
type: ast.
|
|
2861
|
+
type: ast.schema.types.union,
|
|
2841
2862
|
strategy,
|
|
2842
2863
|
members,
|
|
2843
|
-
discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.
|
|
2864
|
+
discriminatorPropertyName: explicitDiscriminatorPropertyName ?? ast.schema.inferDiscriminator(members)
|
|
2844
2865
|
});
|
|
2845
|
-
return ast.
|
|
2866
|
+
return ast.macro.apply(unionNode, [macroDedupeUnion], { depth: "shallow" });
|
|
2846
2867
|
}
|
|
2847
2868
|
/**
|
|
2848
2869
|
* Converts an OAS 3.1 multi-type array (e.g. `type: ['string', 'number']`) into a `UnionSchemaNode`.
|
|
@@ -2859,7 +2880,7 @@ function convertMultiType({ schema, name, nullable, defaultValue, parse }) {
|
|
|
2859
2880
|
nullable: types.includes("null") || nullable || void 0,
|
|
2860
2881
|
defaultValue
|
|
2861
2882
|
}, {
|
|
2862
|
-
type: ast.
|
|
2883
|
+
type: ast.schema.types.union,
|
|
2863
2884
|
members: nonNullTypes.map((t) => {
|
|
2864
2885
|
return parse({
|
|
2865
2886
|
schema: {
|
|
@@ -3138,10 +3159,10 @@ function resolveMapSchema(mapSchema, { options, parse }) {
|
|
|
3138
3159
|
*/
|
|
3139
3160
|
function nameEnums(node, options) {
|
|
3140
3161
|
const macro = macroEnumName(options);
|
|
3141
|
-
const named = ast.
|
|
3142
|
-
const tupleNode = ast.
|
|
3162
|
+
const named = ast.macro.apply(node, [macro], { depth: "shallow" });
|
|
3163
|
+
const tupleNode = ast.schema.narrow(named, "tuple");
|
|
3143
3164
|
if (tupleNode?.items) {
|
|
3144
|
-
const namedItems = tupleNode.items.map((item) => ast.
|
|
3165
|
+
const namedItems = tupleNode.items.map((item) => ast.macro.apply(item, [macro], { depth: "shallow" }));
|
|
3145
3166
|
if (namedItems.some((item, i) => item !== tupleNode.items[i])) return {
|
|
3146
3167
|
...tupleNode,
|
|
3147
3168
|
items: namedItems
|
|
@@ -3224,7 +3245,7 @@ function convertObject({ schema, name, nullable, defaultValue, options, parse, r
|
|
|
3224
3245
|
})
|
|
3225
3246
|
});
|
|
3226
3247
|
const enumName = name ? enumPropName(name, discPropName, options.enumSuffix) : void 0;
|
|
3227
|
-
return ast.
|
|
3248
|
+
return ast.macro.apply(objectNode, [macroDiscriminatorEnum({
|
|
3228
3249
|
propertyName: discPropName,
|
|
3229
3250
|
values,
|
|
3230
3251
|
enumName
|
|
@@ -3468,9 +3489,9 @@ function createSchemaParser(ctx) {
|
|
|
3468
3489
|
}
|
|
3469
3490
|
const presenceKeys = /* @__PURE__ */ new WeakMap();
|
|
3470
3491
|
function requireKeys(keys) {
|
|
3471
|
-
const unknown = ast.factory.createSchema({ type: ast.
|
|
3492
|
+
const unknown = ast.factory.createSchema({ type: ast.schema.types.unknown });
|
|
3472
3493
|
const node = ast.factory.createSchema({
|
|
3473
|
-
type: ast.
|
|
3494
|
+
type: ast.schema.types.object,
|
|
3474
3495
|
primitive: "object",
|
|
3475
3496
|
properties: keys.map((name) => ast.factory.createProperty({
|
|
3476
3497
|
name,
|
|
@@ -3550,8 +3571,8 @@ function createSchemaParser(ctx) {
|
|
|
3550
3571
|
function collectInlineEnums(roots, topLevelNames) {
|
|
3551
3572
|
const promoted = /* @__PURE__ */ new Map();
|
|
3552
3573
|
for (const root of roots) {
|
|
3553
|
-
const isSchemaRoot = root.kind === ast.
|
|
3554
|
-
for (const node of ast.collect(root, { schema: (schemaNode) => schemaNode })) {
|
|
3574
|
+
const isSchemaRoot = root.kind === ast.node.kinds.schema;
|
|
3575
|
+
for (const node of ast.node.collect(root, { schema: (schemaNode) => schemaNode })) {
|
|
3555
3576
|
if (node.type !== "enum" || !node.name) continue;
|
|
3556
3577
|
if (isSchemaRoot && node === root) continue;
|
|
3557
3578
|
if (topLevelNames.has(node.name)) continue;
|
|
@@ -3570,7 +3591,7 @@ function collectInlineEnums(roots, topLevelNames) {
|
|
|
3570
3591
|
*/
|
|
3571
3592
|
function refPromotedEnums(node, promoted) {
|
|
3572
3593
|
if (promoted.size === 0) return node;
|
|
3573
|
-
return ast.transform(node, { schema(schemaNode) {
|
|
3594
|
+
return ast.node.transform(node, { schema(schemaNode) {
|
|
3574
3595
|
if (schemaNode.type !== "enum" || !schemaNode.name || !promoted.has(schemaNode.name)) return void 0;
|
|
3575
3596
|
return ast.factory.createSchema({
|
|
3576
3597
|
type: "ref",
|
|
@@ -3833,7 +3854,7 @@ const adapterOas = defineExtension({
|
|
|
3833
3854
|
const promotedEnums = enums === "root" ? collectInlineEnums([...parsedByName.values(), ...operationNodes], new Set(Object.keys(schemas))) : null;
|
|
3834
3855
|
const aliasTargetOf = (name) => {
|
|
3835
3856
|
const node = refAliasMap.get(name);
|
|
3836
|
-
return node?.ref ? ast.
|
|
3857
|
+
return node?.ref ? ast.ref.getName(node.ref) : node?.name;
|
|
3837
3858
|
};
|
|
3838
3859
|
function isAliasCycle(name) {
|
|
3839
3860
|
const seen = /* @__PURE__ */ new Set([name]);
|