@kubb/adapter-oas 5.0.0-beta.103 → 5.0.0-beta.104
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 +27 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -17
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -2281,15 +2281,20 @@ function refPromotedEnums(node, promoted) {
|
|
|
2281
2281
|
//#endregion
|
|
2282
2282
|
//#region src/schemaDiagnostics.ts
|
|
2283
2283
|
/**
|
|
2284
|
-
*
|
|
2285
|
-
*
|
|
2286
|
-
*
|
|
2287
|
-
*
|
|
2288
|
-
*
|
|
2289
|
-
*
|
|
2284
|
+
* Scans one freshly converted top-level schema in a single walk, so the post-convert pass never
|
|
2285
|
+
* sweeps the same nodes twice. It reports the advisory diagnostics (`KUBB_UNSUPPORTED_FORMAT`,
|
|
2286
|
+
* `KUBB_DEPRECATED`) and returns the names of every schema the node references, ready to feed the
|
|
2287
|
+
* circular-dependency graph.
|
|
2288
|
+
*
|
|
2289
|
+
* Walks the node the parser produced, threading the RFC 6901 pointer as it descends so a nested
|
|
2290
|
+
* field reports against its full path (`#/components/schemas/Pet/properties/owner/properties/name`).
|
|
2291
|
+
* Refs are recorded by name and not followed, so the resolved schema is reported under its own walk.
|
|
2292
|
+
* Reports land in the active build run, are a no-op outside one, and repeats are deduped by the build.
|
|
2290
2293
|
*/
|
|
2291
|
-
function
|
|
2292
|
-
|
|
2294
|
+
function scanSchema({ node, name }) {
|
|
2295
|
+
const refs = /* @__PURE__ */ new Set();
|
|
2296
|
+
visit(node, `#/components/schemas/${escapePointerToken(name)}`, refs);
|
|
2297
|
+
return refs;
|
|
2293
2298
|
}
|
|
2294
2299
|
/**
|
|
2295
2300
|
* Escapes a single JSON pointer reference token per RFC 6901 (`~` → `~0`, `/` → `~1`), so a
|
|
@@ -2298,7 +2303,11 @@ function reportSchemaDiagnostics({ node, name }) {
|
|
|
2298
2303
|
function escapePointerToken(token) {
|
|
2299
2304
|
return token.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
2300
2305
|
}
|
|
2301
|
-
function visit(node, pointer) {
|
|
2306
|
+
function visit(node, pointer, refs) {
|
|
2307
|
+
if (node.type === "ref") {
|
|
2308
|
+
const refName = (0, _kubb_ast.resolveRefName)(node);
|
|
2309
|
+
if (refName) refs.add(refName);
|
|
2310
|
+
}
|
|
2302
2311
|
if (node.deprecated) _kubb_core.Diagnostics.report({
|
|
2303
2312
|
code: _kubb_core.Diagnostics.code.deprecated,
|
|
2304
2313
|
severity: "info",
|
|
@@ -2319,19 +2328,19 @@ function visit(node, pointer) {
|
|
|
2319
2328
|
}
|
|
2320
2329
|
});
|
|
2321
2330
|
if (node.type === "object") {
|
|
2322
|
-
for (const property of node.properties) visit(property.schema, `${pointer}/properties/${escapePointerToken(property.name)}
|
|
2323
|
-
if (node.additionalProperties && typeof node.additionalProperties === "object") visit(node.additionalProperties, `${pointer}/additionalProperties
|
|
2331
|
+
for (const property of node.properties) visit(property.schema, `${pointer}/properties/${escapePointerToken(property.name)}`, refs);
|
|
2332
|
+
if (node.additionalProperties && typeof node.additionalProperties === "object") visit(node.additionalProperties, `${pointer}/additionalProperties`, refs);
|
|
2324
2333
|
return;
|
|
2325
2334
|
}
|
|
2326
2335
|
if (node.type === "array") {
|
|
2327
|
-
for (const item of node.items ?? []) visit(item, `${pointer}/items
|
|
2336
|
+
for (const item of node.items ?? []) visit(item, `${pointer}/items`, refs);
|
|
2328
2337
|
return;
|
|
2329
2338
|
}
|
|
2330
2339
|
if (node.type === "tuple") {
|
|
2331
|
-
for (const [index, item] of (node.items ?? []).entries()) visit(item, `${pointer}/items/${index}
|
|
2340
|
+
for (const [index, item] of (node.items ?? []).entries()) visit(item, `${pointer}/items/${index}`, refs);
|
|
2332
2341
|
return;
|
|
2333
2342
|
}
|
|
2334
|
-
if (node.type === "union" || node.type === "intersection") for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/members/${index}
|
|
2343
|
+
if (node.type === "union" || node.type === "intersection") for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/members/${index}`, refs);
|
|
2335
2344
|
}
|
|
2336
2345
|
//#endregion
|
|
2337
2346
|
//#region src/adapter.ts
|
|
@@ -2384,21 +2393,23 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
|
|
|
2384
2393
|
const refAliasMap = /* @__PURE__ */ new Map();
|
|
2385
2394
|
const enumNames = [];
|
|
2386
2395
|
const discriminatorParentNodes = [];
|
|
2396
|
+
const refGraph = /* @__PURE__ */ new Map();
|
|
2387
2397
|
for (const [name, schema] of Object.entries(schemas)) {
|
|
2388
2398
|
const node = parseSchema({
|
|
2389
2399
|
schema,
|
|
2390
2400
|
name
|
|
2391
2401
|
}, parserOptions);
|
|
2392
2402
|
parsedByName.set(name, node);
|
|
2393
|
-
|
|
2403
|
+
const refs = scanSchema({
|
|
2394
2404
|
node,
|
|
2395
2405
|
name
|
|
2396
2406
|
});
|
|
2407
|
+
if (node.name) refGraph.set(node.name, refs);
|
|
2397
2408
|
if (node.type === "ref" && node.name && node.name !== name) refAliasMap.set(name, node);
|
|
2398
2409
|
if ((0, _kubb_ast.narrowSchema)(node, "enum") && node.name) enumNames.push(node.name);
|
|
2399
2410
|
if (discriminator === "propagate" && (schema.oneOf ?? schema.anyOf) && schema.discriminator?.propertyName) discriminatorParentNodes.push(node);
|
|
2400
2411
|
}
|
|
2401
|
-
const circularNames = [...(0, _kubb_ast.
|
|
2412
|
+
const circularNames = [...(0, _kubb_ast.findCircularSchemasFromGraph)(refGraph)];
|
|
2402
2413
|
const discriminatorChildMap = discriminatorParentNodes.length > 0 ? buildDiscriminatorChildMap(discriminatorParentNodes) : null;
|
|
2403
2414
|
const operationNodes = [];
|
|
2404
2415
|
for (const operation of getOperations(document, refs)) {
|