@kubb/adapter-oas 5.5.5 → 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.js CHANGED
@@ -1335,6 +1335,68 @@ function convertAnnotatedEnum(context) {
1335
1335
  //#endregion
1336
1336
  //#region src/emit/converters/composition.ts
1337
1337
  /**
1338
+ * Collects property schemas from all `allOf` members and outer schema properties,
1339
+ * recursively resolving `$ref` pointers.
1340
+ */
1341
+ function collectSiblingProperties(allOfMembers, refs, outerProperties) {
1342
+ const properties = { ...outerProperties };
1343
+ const visited = /* @__PURE__ */ new Set();
1344
+ function collectFrom(item) {
1345
+ if (!item) return;
1346
+ if (isReference(item)) {
1347
+ if (visited.has(item.$ref)) return;
1348
+ visited.add(item.$ref);
1349
+ const resolved = refs.resolve(item.$ref, { report: false });
1350
+ if (resolved && !isReference(resolved)) collectFrom(resolved);
1351
+ return;
1352
+ }
1353
+ if (item.properties) Object.assign(properties, item.properties);
1354
+ if (Array.isArray(item.allOf)) for (const member of item.allOf) collectFrom(member);
1355
+ }
1356
+ for (const item of allOfMembers) collectFrom(item);
1357
+ return properties;
1358
+ }
1359
+ /**
1360
+ * Enriches union members that declare `required` properties without declaring corresponding
1361
+ * property schemas, populating the missing property definitions from available sibling schemas
1362
+ * (or an empty schema falling back to the configured emptySchemaType).
1363
+ */
1364
+ function resolveUnionMembers(members, siblingProperties) {
1365
+ return members.map((member) => {
1366
+ if (!member || typeof member !== "object" || isReference(member)) return member;
1367
+ const obj = member;
1368
+ if (!Array.isArray(obj.required) || obj.required.length === 0) return member;
1369
+ const existingProps = obj.properties ?? {};
1370
+ const missingKeys = obj.required.filter((key) => !Object.prototype.hasOwnProperty.call(existingProps, key));
1371
+ if (missingKeys.length === 0) return member;
1372
+ const newProperties = { ...existingProps };
1373
+ for (const key of missingKeys) {
1374
+ const value = Object.prototype.hasOwnProperty.call(siblingProperties, key) ? siblingProperties[key] : {};
1375
+ Object.defineProperty(newProperties, key, {
1376
+ value,
1377
+ enumerable: true,
1378
+ writable: true,
1379
+ configurable: true
1380
+ });
1381
+ }
1382
+ return {
1383
+ type: obj.type ?? "object",
1384
+ ...obj,
1385
+ properties: newProperties
1386
+ };
1387
+ });
1388
+ }
1389
+ /**
1390
+ * Enriches any `oneOf` or `anyOf` branches on a schema object with properties from sibling schemas.
1391
+ */
1392
+ function resolveUnionSchema(schema, siblingProperties) {
1393
+ if (!schema.oneOf && !schema.anyOf) return schema;
1394
+ const next = { ...resolveUnionMembers([schema], siblingProperties)[0] ?? schema };
1395
+ if (schema.oneOf) next.oneOf = resolveUnionMembers(schema.oneOf, siblingProperties);
1396
+ if (schema.anyOf) next.anyOf = resolveUnionMembers(schema.anyOf, siblingProperties);
1397
+ return next;
1398
+ }
1399
+ /**
1338
1400
  * Converts a `$ref` schema into a `RefSchemaNode`.
1339
1401
  *
1340
1402
  * The resolved schema is stored in `node.schema`. Usage-site sibling fields
@@ -1394,7 +1456,8 @@ function convertAllOf({ schema, name, nullable, defaultValue, rawOptions, parse,
1394
1456
  name,
1395
1457
  refs
1396
1458
  });
1397
- const allOfMembers = discriminatedAllOf.map((s) => parse({
1459
+ const siblingProperties = collectSiblingProperties(schema.allOf, refs, schema.properties);
1460
+ const allOfMembers = discriminatedAllOf.map((s) => isReference(s) ? s : resolveUnionSchema(s, siblingProperties)).map((s) => parse({
1398
1461
  schema: s,
1399
1462
  name
1400
1463
  }, rawOptions));
@@ -1455,7 +1518,7 @@ function convertUnion(context) {
1455
1518
  nullable,
1456
1519
  defaultValue
1457
1520
  };
1458
- const unionMembers = [...schema.oneOf ?? [], ...schema.anyOf ?? []];
1521
+ const unionMembers = resolveUnionMembers([...schema.oneOf ?? [], ...schema.anyOf ?? []], schema.properties ?? {});
1459
1522
  const strategy = schema.oneOf ? "one" : "any";
1460
1523
  const explicitDiscriminatorPropertyName = isDiscriminator(schema) ? schema.discriminator.propertyName : void 0;
1461
1524
  const discriminator = isDiscriminator(schema) ? schema.discriminator : void 0;
@@ -2312,13 +2375,7 @@ function createSchemaParser(ctx) {
2312
2375
  };
2313
2376
  for (const rule of schemaRules) if (rule.match(context)) return rule.convert(context);
2314
2377
  const emptyType = options.emptySchemaType;
2315
- return ast.factory.createSchema({
2316
- type: emptyType,
2317
- name,
2318
- title: schema.title,
2319
- description: schema.description,
2320
- format: schema.format
2321
- });
2378
+ return createNode(context, { type: emptyType });
2322
2379
  }
2323
2380
  /**
2324
2381
  * Converts a dereferenced OAS parameter object into a `ParameterNode`.