@kubb/adapter-oas 5.0.0-beta.103 → 5.0.0-beta.105

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 CHANGED
@@ -84,12 +84,13 @@ const structuralKeys = /* @__PURE__ */ new Set([
84
84
  ]);
85
85
  /**
86
86
  * Formats `convertFormat` maps to a dedicated type without going through `formatMap`:
87
- * `int64` and the date/time family. Keep this in sync with the `convertFormat`
87
+ * `int64`, `uint64` and the date/time family. Keep this in sync with the `convertFormat`
88
88
  * special-cases in `parser.ts`. `isHandledFormat` reads it so the
89
89
  * `KUBB_UNSUPPORTED_FORMAT` diagnostic and the parser agree on what is handled.
90
90
  */
91
91
  const specialCasedFormats = /* @__PURE__ */ new Set([
92
92
  "int64",
93
+ "uint64",
93
94
  "date-time",
94
95
  "date",
95
96
  "time"
@@ -844,14 +845,14 @@ function getOperations(document, refs) {
844
845
  //#region src/emit/schemaShape.ts
845
846
  /**
846
847
  * Returns the Kubb `SchemaType` for a given OAS `format` string, or `null` if not found.
847
- * Formats not in `formatMap` (e.g., `int64`, `date-time`) are handled separately by parser options.
848
+ * Formats not in `formatMap` (e.g., `int64`, `uint64`, `date-time`) are handled separately by parser options.
848
849
  */
849
850
  function getSchemaType(format) {
850
851
  return formatMap[format] ?? null;
851
852
  }
852
853
  /**
853
854
  * Whether the parser maps `format` to a dedicated type. True for any `formatMap` entry, plus the
854
- * `specialCasedFormats` that `convertFormat` handles directly. False means the format falls back to
855
+ * `specialCasedFormats` that `convertFormat` handles directly (int64, uint64, date-time, date, time). False means the format falls back to
855
856
  * the base type, which is what `KUBB_UNSUPPORTED_FORMAT` flags. Reading both sources keeps the
856
857
  * diagnostic in step with the parser as `formatMap` grows.
857
858
  */
@@ -1369,7 +1370,7 @@ function convertFormat({ schema, name, nullable, defaultValue, options }) {
1369
1370
  nullable,
1370
1371
  defaultValue
1371
1372
  };
1372
- if (schema.format === "int64") return createNode(ctx, {
1373
+ if (schema.format === "int64" || schema.format === "uint64") return createNode(ctx, {
1373
1374
  type: options.integerType === "bigint" ? "bigint" : "integer",
1374
1375
  primitive: "integer",
1375
1376
  min: schema.minimum,
@@ -2281,15 +2282,20 @@ function refPromotedEnums(node, promoted) {
2281
2282
  //#endregion
2282
2283
  //#region src/schemaDiagnostics.ts
2283
2284
  /**
2284
- * Reports the advisory diagnostics (`KUBB_UNSUPPORTED_FORMAT`, `KUBB_DEPRECATED`) for one
2285
- * top-level schema. Walks the node the parser produced, threading the RFC 6901
2286
- * pointer as it descends so a nested field reports against its full path
2287
- * (`#/components/schemas/Pet/properties/owner/properties/name`). Refs are not followed, so the
2288
- * resolved schema is reported under its own walk. Reports land in the active build run, are a
2289
- * no-op outside one, and repeats are deduped by the build.
2285
+ * Scans one freshly converted top-level schema in a single walk, so the post-convert pass never
2286
+ * sweeps the same nodes twice. It reports the advisory diagnostics (`KUBB_UNSUPPORTED_FORMAT`,
2287
+ * `KUBB_DEPRECATED`) and returns the names of every schema the node references, ready to feed the
2288
+ * circular-dependency graph.
2289
+ *
2290
+ * Walks the node the parser produced, threading the RFC 6901 pointer as it descends so a nested
2291
+ * field reports against its full path (`#/components/schemas/Pet/properties/owner/properties/name`).
2292
+ * Refs are recorded by name and not followed, so the resolved schema is reported under its own walk.
2293
+ * Reports land in the active build run, are a no-op outside one, and repeats are deduped by the build.
2290
2294
  */
2291
- function reportSchemaDiagnostics({ node, name }) {
2292
- visit(node, `#/components/schemas/${escapePointerToken(name)}`);
2295
+ function scanSchema({ node, name }) {
2296
+ const refs = /* @__PURE__ */ new Set();
2297
+ visit(node, `#/components/schemas/${escapePointerToken(name)}`, refs);
2298
+ return refs;
2293
2299
  }
2294
2300
  /**
2295
2301
  * Escapes a single JSON pointer reference token per RFC 6901 (`~` → `~0`, `/` → `~1`), so a
@@ -2298,7 +2304,11 @@ function reportSchemaDiagnostics({ node, name }) {
2298
2304
  function escapePointerToken(token) {
2299
2305
  return token.replace(/~/g, "~0").replace(/\//g, "~1");
2300
2306
  }
2301
- function visit(node, pointer) {
2307
+ function visit(node, pointer, refs) {
2308
+ if (node.type === "ref") {
2309
+ const refName = (0, _kubb_ast.resolveRefName)(node);
2310
+ if (refName) refs.add(refName);
2311
+ }
2302
2312
  if (node.deprecated) _kubb_core.Diagnostics.report({
2303
2313
  code: _kubb_core.Diagnostics.code.deprecated,
2304
2314
  severity: "info",
@@ -2319,19 +2329,19 @@ function visit(node, pointer) {
2319
2329
  }
2320
2330
  });
2321
2331
  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`);
2332
+ for (const property of node.properties) visit(property.schema, `${pointer}/properties/${escapePointerToken(property.name)}`, refs);
2333
+ if (node.additionalProperties && typeof node.additionalProperties === "object") visit(node.additionalProperties, `${pointer}/additionalProperties`, refs);
2324
2334
  return;
2325
2335
  }
2326
2336
  if (node.type === "array") {
2327
- for (const item of node.items ?? []) visit(item, `${pointer}/items`);
2337
+ for (const item of node.items ?? []) visit(item, `${pointer}/items`, refs);
2328
2338
  return;
2329
2339
  }
2330
2340
  if (node.type === "tuple") {
2331
- for (const [index, item] of (node.items ?? []).entries()) visit(item, `${pointer}/items/${index}`);
2341
+ for (const [index, item] of (node.items ?? []).entries()) visit(item, `${pointer}/items/${index}`, refs);
2332
2342
  return;
2333
2343
  }
2334
- if (node.type === "union" || node.type === "intersection") for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/members/${index}`);
2344
+ if (node.type === "union" || node.type === "intersection") for (const [index, member] of (node.members ?? []).entries()) visit(member, `${pointer}/members/${index}`, refs);
2335
2345
  }
2336
2346
  //#endregion
2337
2347
  //#region src/adapter.ts
@@ -2384,21 +2394,23 @@ const adapterOas = (0, _kubb_core.createAdapter)((options) => {
2384
2394
  const refAliasMap = /* @__PURE__ */ new Map();
2385
2395
  const enumNames = [];
2386
2396
  const discriminatorParentNodes = [];
2397
+ const refGraph = /* @__PURE__ */ new Map();
2387
2398
  for (const [name, schema] of Object.entries(schemas)) {
2388
2399
  const node = parseSchema({
2389
2400
  schema,
2390
2401
  name
2391
2402
  }, parserOptions);
2392
2403
  parsedByName.set(name, node);
2393
- reportSchemaDiagnostics({
2404
+ const refs = scanSchema({
2394
2405
  node,
2395
2406
  name
2396
2407
  });
2408
+ if (node.name) refGraph.set(node.name, refs);
2397
2409
  if (node.type === "ref" && node.name && node.name !== name) refAliasMap.set(name, node);
2398
2410
  if ((0, _kubb_ast.narrowSchema)(node, "enum") && node.name) enumNames.push(node.name);
2399
2411
  if (discriminator === "propagate" && (schema.oneOf ?? schema.anyOf) && schema.discriminator?.propertyName) discriminatorParentNodes.push(node);
2400
2412
  }
2401
- const circularNames = [...(0, _kubb_ast.findCircularSchemas)([...parsedByName.values()])];
2413
+ const circularNames = [...(0, _kubb_ast.findCircularSchemasFromGraph)(refGraph)];
2402
2414
  const discriminatorChildMap = discriminatorParentNodes.length > 0 ? buildDiscriminatorChildMap(discriminatorParentNodes) : null;
2403
2415
  const operationNodes = [];
2404
2416
  for (const operation of getOperations(document, refs)) {