@kubb/adapter-oas 5.29.3 → 5.29.5
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 +30 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -20
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -15,7 +15,7 @@ var compatibility = {
|
|
|
15
15
|
"node": ">=22.22"
|
|
16
16
|
};
|
|
17
17
|
// package.json
|
|
18
|
-
var version = "5.29.
|
|
18
|
+
var version = "5.29.5";
|
|
19
19
|
// src/constants.ts
|
|
20
20
|
/**
|
|
21
21
|
* Default parser options applied when no explicit options are provided.
|
|
@@ -171,9 +171,6 @@ const enumExtensionKeys = ["x-enumNames", "x-enum-varnames"];
|
|
|
171
171
|
*/
|
|
172
172
|
const enumDescriptionKeys = ["x-enumDescriptions", "x-enum-descriptions"];
|
|
173
173
|
// src/emit/discriminator/propagate.ts
|
|
174
|
-
function findUnion(schema) {
|
|
175
|
-
return _kubb_kit.ast.schema.narrow(schema, "union") ?? _kubb_kit.ast.schema.narrow(schema, "intersection")?.members?.map((member) => _kubb_kit.ast.schema.narrow(member, "union")).find((union) => union);
|
|
176
|
-
}
|
|
177
174
|
function pinnedValues({ objNode, propertyName }) {
|
|
178
175
|
const prop = objNode.properties.find((p) => p.name === propertyName);
|
|
179
176
|
return (prop ? _kubb_kit.ast.schema.narrow(prop.schema, "enum") : null)?.enumValues?.filter((v) => v !== null) ?? [];
|
|
@@ -193,17 +190,19 @@ function memberDiscriminant({ member, propertyName }) {
|
|
|
193
190
|
} : null;
|
|
194
191
|
}
|
|
195
192
|
/**
|
|
196
|
-
* Maps each child schema's emitted name to its discriminator patch data by scanning the given
|
|
197
|
-
*
|
|
193
|
+
* Maps each child schema's emitted name to its discriminator patch data, one entry per discriminator property, by scanning the given
|
|
194
|
+
* AST schema nodes, and the schemas nested in them, for union schemas that carry a `discriminatorPropertyName`.
|
|
195
|
+
* A union can sit at the root, inside an intersection (a union with shared properties), on a property, or on array `items`.
|
|
196
|
+
* Ref targets are not followed.
|
|
198
197
|
*
|
|
199
198
|
* Called on a small pre-parsed subset of schemas (only the discriminator parents)
|
|
200
199
|
* rather than on all schemas at once.
|
|
201
200
|
*/
|
|
202
201
|
function buildDiscriminatorChildMap(schemas) {
|
|
203
202
|
const childMap = /* @__PURE__ */ new Map();
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (!unionNode
|
|
203
|
+
const unions = schemas.flatMap((schema) => _kubb_kit.ast.node.collect(schema, { schema: (node) => _kubb_kit.ast.schema.narrow(node, "union") }));
|
|
204
|
+
for (const unionNode of unions) {
|
|
205
|
+
if (!unionNode.discriminatorPropertyName || !unionNode.members) continue;
|
|
207
206
|
const propertyName = unionNode.discriminatorPropertyName;
|
|
208
207
|
for (const member of unionNode.members) {
|
|
209
208
|
const child = memberDiscriminant({
|
|
@@ -211,12 +210,14 @@ function buildDiscriminatorChildMap(schemas) {
|
|
|
211
210
|
propertyName
|
|
212
211
|
});
|
|
213
212
|
if (!child) continue;
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
213
|
+
const targets = childMap.get(child.name) ?? [];
|
|
214
|
+
const existing = targets.find((target) => target.propertyName === propertyName);
|
|
215
|
+
if (existing) existing.enumValues = [.../* @__PURE__ */ new Set([...existing.enumValues, ...child.enumValues])];
|
|
216
|
+
else targets.push({
|
|
217
|
+
propertyName,
|
|
218
|
+
enumValues: child.enumValues
|
|
219
219
|
});
|
|
220
|
+
childMap.set(child.name, targets);
|
|
220
221
|
}
|
|
221
222
|
}
|
|
222
223
|
return childMap;
|
|
@@ -4008,8 +4009,10 @@ function convertObject({ schema, name, nullable, defaultValue, options, parse, r
|
|
|
4008
4009
|
* Converts an OAS 3.1 `prefixItems` tuple into a `TupleSchemaNode`.
|
|
4009
4010
|
*/
|
|
4010
4011
|
function convertTuple({ schema, name, nullable, defaultValue, options, parse }) {
|
|
4011
|
-
const
|
|
4012
|
-
const
|
|
4012
|
+
const prefixItems = schema.prefixItems ?? [];
|
|
4013
|
+
const isClosed = schema.maxItems !== void 0 && schema.maxItems <= prefixItems.length;
|
|
4014
|
+
const tupleItems = (isClosed ? prefixItems.slice(0, schema.maxItems) : prefixItems).map((item) => parse({ schema: item }));
|
|
4015
|
+
const tail = isClosed ? false : schema.items ?? schema.unevaluatedItems;
|
|
4013
4016
|
const rest = tail === false ? void 0 : !tail || tail === true ? _kubb_kit.ast.factory.createSchema({ type: options.unknownType }) : parse({ schema: tail });
|
|
4014
4017
|
return createNode({
|
|
4015
4018
|
schema,
|
|
@@ -4559,8 +4562,16 @@ var Adapter = class {
|
|
|
4559
4562
|
};
|
|
4560
4563
|
}
|
|
4561
4564
|
};
|
|
4562
|
-
|
|
4563
|
-
|
|
4565
|
+
/**
|
|
4566
|
+
* Returns `true` when the schema, or any schema nested in it, is a `oneOf`/`anyOf` with a discriminator,
|
|
4567
|
+
* such as a union declared on a property or on array `items`.
|
|
4568
|
+
*/
|
|
4569
|
+
function isDiscriminatorParent(schema, seen = /* @__PURE__ */ new WeakSet()) {
|
|
4570
|
+
if (!schema || typeof schema !== "object" || seen.has(schema)) return false;
|
|
4571
|
+
seen.add(schema);
|
|
4572
|
+
const { oneOf, anyOf, discriminator } = schema;
|
|
4573
|
+
if ((oneOf ?? anyOf) && discriminator?.propertyName) return true;
|
|
4574
|
+
return Object.values(schema).some((value) => isDiscriminatorParent(value, seen));
|
|
4564
4575
|
}
|
|
4565
4576
|
function resolveSchemaNodes({ names, parsed: { parsedByName, refAliasMap, discriminatorChildMap }, promotedEnums }) {
|
|
4566
4577
|
const aliasTargetOf = (name) => {
|
|
@@ -4581,8 +4592,7 @@ function resolveSchemaNodes({ names, parsed: { parsedByName, refAliasMap, discri
|
|
|
4581
4592
|
const aliasTarget = refAliasMap.get(name)?.name;
|
|
4582
4593
|
const aliased = aliasTarget ? parsedByName.get(aliasTarget) : void 0;
|
|
4583
4594
|
const parsed = parsedByName.get(name);
|
|
4584
|
-
const
|
|
4585
|
-
const base = child ? patchDiscriminatorNode(parsed, child) : parsed;
|
|
4595
|
+
const base = (discriminatorChildMap?.get(name) ?? []).reduce(patchDiscriminatorNode, parsed);
|
|
4586
4596
|
const resolved = aliased ? {
|
|
4587
4597
|
...aliased,
|
|
4588
4598
|
name,
|