@kubb/adapter-oas 5.5.4 → 5.5.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 CHANGED
@@ -452,7 +452,7 @@ async function resolveSource(sourcePath) {
452
452
  * its parse error instead.
453
453
  */
454
454
  async function assertInputExists(input) {
455
- if (URL.canParse(input)) return;
455
+ if (urlRegExp.test(input)) return;
456
456
  if (!await exists(input)) throw new _kubb_core.Diagnostics.Error({
457
457
  code: _kubb_core.Diagnostics.code.inputNotFound,
458
458
  severity: "error",
@@ -541,7 +541,7 @@ async function parseDocument(pathOrApi) {
541
541
  */
542
542
  async function parseFromConfig(source) {
543
543
  if (source.type === "data") return parseDocument(typeof source.data === "string" ? (0, yaml.parse)(source.data) : structuredClone(source.data));
544
- if (URL.canParse(source.path)) return parseDocument(source.path);
544
+ if (urlRegExp.test(source.path)) return parseDocument(source.path);
545
545
  const resolved = node_path.default.resolve(node_path.default.dirname(source.path), source.path);
546
546
  await assertInputExists(resolved);
547
547
  return parseDocument(resolved);
@@ -1358,6 +1358,68 @@ function convertAnnotatedEnum(context) {
1358
1358
  //#endregion
1359
1359
  //#region src/emit/converters/composition.ts
1360
1360
  /**
1361
+ * Collects property schemas from all `allOf` members and outer schema properties,
1362
+ * recursively resolving `$ref` pointers.
1363
+ */
1364
+ function collectSiblingProperties(allOfMembers, refs, outerProperties) {
1365
+ const properties = { ...outerProperties };
1366
+ const visited = /* @__PURE__ */ new Set();
1367
+ function collectFrom(item) {
1368
+ if (!item) return;
1369
+ if (isReference(item)) {
1370
+ if (visited.has(item.$ref)) return;
1371
+ visited.add(item.$ref);
1372
+ const resolved = refs.resolve(item.$ref, { report: false });
1373
+ if (resolved && !isReference(resolved)) collectFrom(resolved);
1374
+ return;
1375
+ }
1376
+ if (item.properties) Object.assign(properties, item.properties);
1377
+ if (Array.isArray(item.allOf)) for (const member of item.allOf) collectFrom(member);
1378
+ }
1379
+ for (const item of allOfMembers) collectFrom(item);
1380
+ return properties;
1381
+ }
1382
+ /**
1383
+ * Enriches union members that declare `required` properties without declaring corresponding
1384
+ * property schemas, populating the missing property definitions from available sibling schemas
1385
+ * (or an empty schema falling back to the configured emptySchemaType).
1386
+ */
1387
+ function resolveUnionMembers(members, siblingProperties) {
1388
+ return members.map((member) => {
1389
+ if (!member || typeof member !== "object" || isReference(member)) return member;
1390
+ const obj = member;
1391
+ if (!Array.isArray(obj.required) || obj.required.length === 0) return member;
1392
+ const existingProps = obj.properties ?? {};
1393
+ const missingKeys = obj.required.filter((key) => !Object.prototype.hasOwnProperty.call(existingProps, key));
1394
+ if (missingKeys.length === 0) return member;
1395
+ const newProperties = { ...existingProps };
1396
+ for (const key of missingKeys) {
1397
+ const value = Object.prototype.hasOwnProperty.call(siblingProperties, key) ? siblingProperties[key] : {};
1398
+ Object.defineProperty(newProperties, key, {
1399
+ value,
1400
+ enumerable: true,
1401
+ writable: true,
1402
+ configurable: true
1403
+ });
1404
+ }
1405
+ return {
1406
+ type: obj.type ?? "object",
1407
+ ...obj,
1408
+ properties: newProperties
1409
+ };
1410
+ });
1411
+ }
1412
+ /**
1413
+ * Enriches any `oneOf` or `anyOf` branches on a schema object with properties from sibling schemas.
1414
+ */
1415
+ function resolveUnionSchema(schema, siblingProperties) {
1416
+ if (!schema.oneOf && !schema.anyOf) return schema;
1417
+ const next = { ...resolveUnionMembers([schema], siblingProperties)[0] ?? schema };
1418
+ if (schema.oneOf) next.oneOf = resolveUnionMembers(schema.oneOf, siblingProperties);
1419
+ if (schema.anyOf) next.anyOf = resolveUnionMembers(schema.anyOf, siblingProperties);
1420
+ return next;
1421
+ }
1422
+ /**
1361
1423
  * Converts a `$ref` schema into a `RefSchemaNode`.
1362
1424
  *
1363
1425
  * The resolved schema is stored in `node.schema`. Usage-site sibling fields
@@ -1417,7 +1479,8 @@ function convertAllOf({ schema, name, nullable, defaultValue, rawOptions, parse,
1417
1479
  name,
1418
1480
  refs
1419
1481
  });
1420
- const allOfMembers = discriminatedAllOf.map((s) => parse({
1482
+ const siblingProperties = collectSiblingProperties(schema.allOf, refs, schema.properties);
1483
+ const allOfMembers = discriminatedAllOf.map((s) => isReference(s) ? s : resolveUnionSchema(s, siblingProperties)).map((s) => parse({
1421
1484
  schema: s,
1422
1485
  name
1423
1486
  }, rawOptions));
@@ -1478,7 +1541,7 @@ function convertUnion(context) {
1478
1541
  nullable,
1479
1542
  defaultValue
1480
1543
  };
1481
- const unionMembers = [...schema.oneOf ?? [], ...schema.anyOf ?? []];
1544
+ const unionMembers = resolveUnionMembers([...schema.oneOf ?? [], ...schema.anyOf ?? []], schema.properties ?? {});
1482
1545
  const strategy = schema.oneOf ? "one" : "any";
1483
1546
  const explicitDiscriminatorPropertyName = isDiscriminator(schema) ? schema.discriminator.propertyName : void 0;
1484
1547
  const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
@@ -2016,7 +2079,7 @@ function walkPointer(document, $ref) {
2016
2079
  applicable: false,
2017
2080
  value: null
2018
2081
  };
2019
- const pointer = globalThis.decodeURIComponent(trimmed.substring(1));
2082
+ const pointer = trimmed.substring(1);
2020
2083
  let docCache = _refCache.get(document);
2021
2084
  if (!docCache) {
2022
2085
  docCache = /* @__PURE__ */ new Map();
@@ -2026,7 +2089,7 @@ function walkPointer(document, $ref) {
2026
2089
  applicable: true,
2027
2090
  value: docCache.get(pointer)
2028
2091
  };
2029
- const current = pointer.split("/").filter(Boolean).reduce((obj, key) => obj?.[key], document);
2092
+ const current = pointer.split("/").filter(Boolean).map((token) => globalThis.decodeURIComponent(token).replaceAll("~1", "/").replaceAll("~0", "~")).reduce((obj, key) => obj?.[key], document);
2030
2093
  if (current) docCache.set(pointer, current);
2031
2094
  return {
2032
2095
  applicable: true,
@@ -2335,13 +2398,7 @@ function createSchemaParser(ctx) {
2335
2398
  };
2336
2399
  for (const rule of schemaRules) if (rule.match(context)) return rule.convert(context);
2337
2400
  const emptyType = options.emptySchemaType;
2338
- return _kubb_ast.ast.factory.createSchema({
2339
- type: emptyType,
2340
- name,
2341
- title: schema.title,
2342
- description: schema.description,
2343
- format: schema.format
2344
- });
2401
+ return createNode(context, { type: emptyType });
2345
2402
  }
2346
2403
  /**
2347
2404
  * Converts a dereferenced OAS parameter object into a `ParameterNode`.