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