@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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { ast, findCircularSchemas, narrowSchema } from "@kubb/ast";
2
+ import { ast, findCircularSchemasFromGraph, narrowSchema, resolveRefName } from "@kubb/ast";
3
3
  import { Diagnostics, createAdapter } from "@kubb/core";
4
4
  import { access, readFile } from "node:fs/promises";
5
5
  import path from "node:path";
@@ -2258,15 +2258,20 @@ function refPromotedEnums(node, promoted) {
2258
2258
  //#endregion
2259
2259
  //#region src/schemaDiagnostics.ts
2260
2260
  /**
2261
- * Reports the advisory diagnostics (`KUBB_UNSUPPORTED_FORMAT`, `KUBB_DEPRECATED`) for one
2262
- * top-level schema. Walks the node the parser produced, threading the RFC 6901
2263
- * pointer as it descends so a nested field reports against its full path
2264
- * (`#/components/schemas/Pet/properties/owner/properties/name`). Refs are not followed, so the
2265
- * resolved schema is reported under its own walk. Reports land in the active build run, are a
2266
- * no-op outside one, and repeats are deduped by the build.
2261
+ * Scans one freshly converted top-level schema in a single walk, so the post-convert pass never
2262
+ * sweeps the same nodes twice. It reports the advisory diagnostics (`KUBB_UNSUPPORTED_FORMAT`,
2263
+ * `KUBB_DEPRECATED`) and returns the names of every schema the node references, ready to feed the
2264
+ * circular-dependency graph.
2265
+ *
2266
+ * Walks the node the parser produced, threading the RFC 6901 pointer as it descends so a nested
2267
+ * field reports against its full path (`#/components/schemas/Pet/properties/owner/properties/name`).
2268
+ * Refs are recorded by name and not followed, so the resolved schema is reported under its own walk.
2269
+ * Reports land in the active build run, are a no-op outside one, and repeats are deduped by the build.
2267
2270
  */
2268
- function reportSchemaDiagnostics({ node, name }) {
2269
- visit(node, `#/components/schemas/${escapePointerToken(name)}`);
2271
+ function scanSchema({ node, name }) {
2272
+ const refs = /* @__PURE__ */ new Set();
2273
+ visit(node, `#/components/schemas/${escapePointerToken(name)}`, refs);
2274
+ return refs;
2270
2275
  }
2271
2276
  /**
2272
2277
  * Escapes a single JSON pointer reference token per RFC 6901 (`~` → `~0`, `/` → `~1`), so a
@@ -2275,7 +2280,11 @@ function reportSchemaDiagnostics({ node, name }) {
2275
2280
  function escapePointerToken(token) {
2276
2281
  return token.replace(/~/g, "~0").replace(/\//g, "~1");
2277
2282
  }
2278
- function visit(node, pointer) {
2283
+ function visit(node, pointer, refs) {
2284
+ if (node.type === "ref") {
2285
+ const refName = resolveRefName(node);
2286
+ if (refName) refs.add(refName);
2287
+ }
2279
2288
  if (node.deprecated) Diagnostics.report({
2280
2289
  code: Diagnostics.code.deprecated,
2281
2290
  severity: "info",
@@ -2296,19 +2305,19 @@ function visit(node, pointer) {
2296
2305
  }
2297
2306
  });
2298
2307
  if (node.type === "object") {
2299
- for (const property of node.properties) visit(property.schema, `${pointer}/properties/${escapePointerToken(property.name)}`);
2300
- if (node.additionalProperties && typeof node.additionalProperties === "object") visit(node.additionalProperties, `${pointer}/additionalProperties`);
2308
+ for (const property of node.properties) visit(property.schema, `${pointer}/properties/${escapePointerToken(property.name)}`, refs);
2309
+ if (node.additionalProperties && typeof node.additionalProperties === "object") visit(node.additionalProperties, `${pointer}/additionalProperties`, refs);
2301
2310
  return;
2302
2311
  }
2303
2312
  if (node.type === "array") {
2304
- for (const item of node.items ?? []) visit(item, `${pointer}/items`);
2313
+ for (const item of node.items ?? []) visit(item, `${pointer}/items`, refs);
2305
2314
  return;
2306
2315
  }
2307
2316
  if (node.type === "tuple") {
2308
- for (const [index, item] of (node.items ?? []).entries()) visit(item, `${pointer}/items/${index}`);
2317
+ for (const [index, item] of (node.items ?? []).entries()) visit(item, `${pointer}/items/${index}`, refs);
2309
2318
  return;
2310
2319
  }
2311
- if (node.type === "union" || node.type === "intersection") for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/members/${index}`);
2320
+ if (node.type === "union" || node.type === "intersection") for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/members/${index}`, refs);
2312
2321
  }
2313
2322
  //#endregion
2314
2323
  //#region src/adapter.ts
@@ -2361,21 +2370,23 @@ const adapterOas = createAdapter((options) => {
2361
2370
  const refAliasMap = /* @__PURE__ */ new Map();
2362
2371
  const enumNames = [];
2363
2372
  const discriminatorParentNodes = [];
2373
+ const refGraph = /* @__PURE__ */ new Map();
2364
2374
  for (const [name, schema] of Object.entries(schemas)) {
2365
2375
  const node = parseSchema({
2366
2376
  schema,
2367
2377
  name
2368
2378
  }, parserOptions);
2369
2379
  parsedByName.set(name, node);
2370
- reportSchemaDiagnostics({
2380
+ const refs = scanSchema({
2371
2381
  node,
2372
2382
  name
2373
2383
  });
2384
+ if (node.name) refGraph.set(node.name, refs);
2374
2385
  if (node.type === "ref" && node.name && node.name !== name) refAliasMap.set(name, node);
2375
2386
  if (narrowSchema(node, "enum") && node.name) enumNames.push(node.name);
2376
2387
  if (discriminator === "propagate" && (schema.oneOf ?? schema.anyOf) && schema.discriminator?.propertyName) discriminatorParentNodes.push(node);
2377
2388
  }
2378
- const circularNames = [...findCircularSchemas([...parsedByName.values()])];
2389
+ const circularNames = [...findCircularSchemasFromGraph(refGraph)];
2379
2390
  const discriminatorChildMap = discriminatorParentNodes.length > 0 ? buildDiscriminatorChildMap(discriminatorParentNodes) : null;
2380
2391
  const operationNodes = [];
2381
2392
  for (const operation of getOperations(document, refs)) {