@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 +70 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -13
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -429,7 +429,7 @@ async function resolveSource(sourcePath) {
|
|
|
429
429
|
* its parse error instead.
|
|
430
430
|
*/
|
|
431
431
|
async function assertInputExists(input) {
|
|
432
|
-
if (
|
|
432
|
+
if (urlRegExp.test(input)) return;
|
|
433
433
|
if (!await exists(input)) throw new Diagnostics.Error({
|
|
434
434
|
code: Diagnostics.code.inputNotFound,
|
|
435
435
|
severity: "error",
|
|
@@ -518,7 +518,7 @@ async function parseDocument(pathOrApi) {
|
|
|
518
518
|
*/
|
|
519
519
|
async function parseFromConfig(source) {
|
|
520
520
|
if (source.type === "data") return parseDocument(typeof source.data === "string" ? parse(source.data) : structuredClone(source.data));
|
|
521
|
-
if (
|
|
521
|
+
if (urlRegExp.test(source.path)) return parseDocument(source.path);
|
|
522
522
|
const resolved = path.resolve(path.dirname(source.path), source.path);
|
|
523
523
|
await assertInputExists(resolved);
|
|
524
524
|
return parseDocument(resolved);
|
|
@@ -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
|
|
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;
|
|
@@ -1993,7 +2056,7 @@ function walkPointer(document, $ref) {
|
|
|
1993
2056
|
applicable: false,
|
|
1994
2057
|
value: null
|
|
1995
2058
|
};
|
|
1996
|
-
const pointer =
|
|
2059
|
+
const pointer = trimmed.substring(1);
|
|
1997
2060
|
let docCache = _refCache.get(document);
|
|
1998
2061
|
if (!docCache) {
|
|
1999
2062
|
docCache = /* @__PURE__ */ new Map();
|
|
@@ -2003,7 +2066,7 @@ function walkPointer(document, $ref) {
|
|
|
2003
2066
|
applicable: true,
|
|
2004
2067
|
value: docCache.get(pointer)
|
|
2005
2068
|
};
|
|
2006
|
-
const current = pointer.split("/").filter(Boolean).reduce((obj, key) => obj?.[key], document);
|
|
2069
|
+
const current = pointer.split("/").filter(Boolean).map((token) => globalThis.decodeURIComponent(token).replaceAll("~1", "/").replaceAll("~0", "~")).reduce((obj, key) => obj?.[key], document);
|
|
2007
2070
|
if (current) docCache.set(pointer, current);
|
|
2008
2071
|
return {
|
|
2009
2072
|
applicable: true,
|
|
@@ -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
|
|
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`.
|