@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.cjs +66 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +66 -9
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -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
|
|
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;
|
|
@@ -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
|
|
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`.
|