@kubb/adapter-oas 5.29.1 → 5.29.3

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.d.cts CHANGED
@@ -1277,12 +1277,11 @@ type ServerOptions = {
1277
1277
  */
1278
1278
  type AdapterOasOptions = {
1279
1279
  /**
1280
- * Validate the OpenAPI spec with `@readme/openapi-parser` before parsing. Each problem is
1281
- * reported as a `KUBB_INVALID_SPEC` warning and generation continues. Set to `false` to skip the
1282
- * check, which also makes generation faster on a large spec. An OpenAPI 3.2 document is not
1283
- * validated yet and gets one warning that says so.
1280
+ * Check the OpenAPI spec with `@readme/openapi-parser` while generating, and report each problem
1281
+ * as a `KUBB_INVALID_SPEC` warning without stopping the build. The check is off by default
1282
+ * because it slows down a large spec. Run `kubb validate` to check a spec on its own.
1284
1283
  *
1285
- * @default true
1284
+ * @default false
1286
1285
  */
1287
1286
  validate?: boolean;
1288
1287
  /**
@@ -1355,9 +1354,9 @@ type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasReso
1355
1354
  export declare const adapterOasName = "oas";
1356
1355
  /**
1357
1356
  * Default Kubb adapter for OpenAPI 2.0, 3.0, 3.1, and 3.2 specifications. Reads the
1358
- * spec from `input` (a file path, URL, inline content, or parsed object), validates
1359
- * it, resolves the base URL, and converts every schema and operation into the
1360
- * universal AST that every downstream plugin consumes.
1357
+ * spec from `input` (a file path, URL, inline content, or parsed object), resolves
1358
+ * the base URL, and converts every schema and operation into the universal AST that
1359
+ * every downstream plugin consumes. Set `validate: true` to also check the spec.
1361
1360
  *
1362
1361
  * Configure once on `defineConfig`. The adapter's choices (date representation,
1363
1362
  * integer width, server URL) apply to every plugin in the build.
package/dist/index.d.ts CHANGED
@@ -1277,12 +1277,11 @@ type ServerOptions = {
1277
1277
  */
1278
1278
  type AdapterOasOptions = {
1279
1279
  /**
1280
- * Validate the OpenAPI spec with `@readme/openapi-parser` before parsing. Each problem is
1281
- * reported as a `KUBB_INVALID_SPEC` warning and generation continues. Set to `false` to skip the
1282
- * check, which also makes generation faster on a large spec. An OpenAPI 3.2 document is not
1283
- * validated yet and gets one warning that says so.
1280
+ * Check the OpenAPI spec with `@readme/openapi-parser` while generating, and report each problem
1281
+ * as a `KUBB_INVALID_SPEC` warning without stopping the build. The check is off by default
1282
+ * because it slows down a large spec. Run `kubb validate` to check a spec on its own.
1284
1283
  *
1285
- * @default true
1284
+ * @default false
1286
1285
  */
1287
1286
  validate?: boolean;
1288
1287
  /**
@@ -1355,9 +1354,9 @@ type AdapterOas = AdapterFactoryOptions<'oas', AdapterOasOptions, AdapterOasReso
1355
1354
  export declare const adapterOasName = "oas";
1356
1355
  /**
1357
1356
  * Default Kubb adapter for OpenAPI 2.0, 3.0, 3.1, and 3.2 specifications. Reads the
1358
- * spec from `input` (a file path, URL, inline content, or parsed object), validates
1359
- * it, resolves the base URL, and converts every schema and operation into the
1360
- * universal AST that every downstream plugin consumes.
1357
+ * spec from `input` (a file path, URL, inline content, or parsed object), resolves
1358
+ * the base URL, and converts every schema and operation into the universal AST that
1359
+ * every downstream plugin consumes. Set `validate: true` to also check the spec.
1361
1360
  *
1362
1361
  * Configure once on `defineConfig`. The adapter's choices (date representation,
1363
1362
  * integer width, server URL) apply to every plugin in the build.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import "./rolldown-runtime-BowF1xt-.js";
2
2
  import { defineExtension, pascalCase } from "@kubb/core";
3
3
  import { Diagnostics, Url, ast, childName, enumPrimitive, enumPropName, macroDedupeUnion, macroDiscriminatorEnum, macroEnumName, mergeAdjacentObjectsLazy } from "@kubb/kit";
4
- import { dirname, join, resolve } from "node:path";
4
+ import { dirname, join, normalize, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { upgrade } from "@scalar/openapi-upgrader";
7
- import { bundle, parseRef } from "api-ref-bundler";
7
+ import { bundle } from "api-ref-bundler";
8
8
  import { readFile } from "node:fs";
9
9
  import { access } from "node:fs/promises";
10
10
  import { COLLECTION_STYLE, CORE_SCHEMA, EVENT_ID, SCALAR_STYLE, constructFromEvents, load, parseEvents } from "js-yaml";
@@ -14,7 +14,7 @@ var compatibility = {
14
14
  "node": ">=22.22"
15
15
  };
16
16
  // package.json
17
- var version = "5.29.1";
17
+ var version = "5.29.3";
18
18
  // src/constants.ts
19
19
  /**
20
20
  * Default parser options applied when no explicit options are provided.
@@ -1246,6 +1246,18 @@ function isExtensionPath(path) {
1246
1246
  return false;
1247
1247
  }
1248
1248
  /**
1249
+ * True when `node` is the value at `path` in `document`. api-ref-bundler reports the output path of a
1250
+ * failed `$ref`, so this tells a `$ref` in the input itself from one in a file it pulled in.
1251
+ */
1252
+ function isNodeAt(document, path, node) {
1253
+ let current = document;
1254
+ for (const token of path) {
1255
+ if (!current || typeof current !== "object" || !Object.hasOwn(current, token)) return false;
1256
+ current = current[token];
1257
+ }
1258
+ return current === node;
1259
+ }
1260
+ /**
1249
1261
  * Returns the base for relative `$ref`s: the 3.2 `$self` resolved against `pathOrUrl`, else `pathOrUrl`.
1250
1262
  */
1251
1263
  function getBaseUri(pathOrUrl, root) {
@@ -1289,7 +1301,7 @@ function getBaseUri(pathOrUrl, root) {
1289
1301
  */
1290
1302
  async function bundleDocument(pathOrUrl, { document, sources = [], harness, signal } = {}) {
1291
1303
  const cache = memo.create();
1292
- const toKey = (sourcePath) => urlRegExp.test(sourcePath) ? new URL(sourcePath).href : sourcePath;
1304
+ const toKey = (sourcePath) => urlRegExp.test(sourcePath) ? new URL(sourcePath).href : normalize(sourcePath);
1293
1305
  const refused = /* @__PURE__ */ new Set();
1294
1306
  const harnessRefusals = /* @__PURE__ */ new Map();
1295
1307
  const read = ({ sourcePath, isRef }) => {
@@ -1307,10 +1319,6 @@ async function bundleDocument(pathOrUrl, { document, sources = [], harness, sign
1307
1319
  throw error;
1308
1320
  });
1309
1321
  };
1310
- const refTarget = ({ value, baseFile }) => {
1311
- const ref = value?.$ref;
1312
- return typeof ref === "string" ? toKey(parseRef(ref, baseFile).filePath) : void 0;
1313
- };
1314
1322
  const refDiagnostic = ({ message, target }) => {
1315
1323
  const harnessRefusal = target === void 0 ? void 0 : harnessRefusals.get(target);
1316
1324
  if (harnessRefusal) return harnessRefusal;
@@ -1353,16 +1361,13 @@ async function bundleDocument(pathOrUrl, { document, sources = [], harness, sign
1353
1361
  }
1354
1362
  entry = getBaseUri(pathOrUrl, root);
1355
1363
  entryDocument = root;
1356
- return await bundle(entry, resolver, { hooks: { onError: (message, { path, state, value }) => {
1364
+ return await bundle(entry, resolver, { hooks: { onError: (message, { path, value }, detail) => {
1357
1365
  signal?.throwIfAborted();
1358
- const pointer = toKey(state.baseFile) === toKey(entry) ? `#/${path.map((token) => escapePointerToken(String(token))).join("/")}` : void 0;
1366
+ const pointer = isNodeAt(root, path, value) ? `#/${path.map((token) => escapePointerToken(String(token))).join("/")}` : void 0;
1359
1367
  const diagnostic = {
1360
1368
  ...refDiagnostic({
1361
1369
  message,
1362
- target: refTarget({
1363
- value,
1364
- baseFile: state.baseFile
1365
- })
1370
+ target: detail && toKey(detail.document)
1366
1371
  }),
1367
1372
  severity: isExtensionPath(path) ? "warning" : "error",
1368
1373
  ...pointer && { location: {
@@ -4639,9 +4644,9 @@ function toInputMeta({ document, server, authSchemes }) {
4639
4644
  }
4640
4645
  /**
4641
4646
  * Default Kubb adapter for OpenAPI 2.0, 3.0, 3.1, and 3.2 specifications. Reads the
4642
- * spec from `input` (a file path, URL, inline content, or parsed object), validates
4643
- * it, resolves the base URL, and converts every schema and operation into the
4644
- * universal AST that every downstream plugin consumes.
4647
+ * spec from `input` (a file path, URL, inline content, or parsed object), resolves
4648
+ * the base URL, and converts every schema and operation into the universal AST that
4649
+ * every downstream plugin consumes. Set `validate: true` to also check the spec.
4645
4650
  *
4646
4651
  * Configure once on `defineConfig`. The adapter's choices (date representation,
4647
4652
  * integer width, server URL) apply to every plugin in the build.
@@ -4672,7 +4677,7 @@ const adapterOas = defineExtension({
4672
4677
  compatibility,
4673
4678
  issues: "https://github.com/kubb-labs/kubb/issues"
4674
4679
  },
4675
- setup: ({ validate = true, contentType, server, discriminator = "preserve", enums = "inline", pathParamsCasing, dateType = DEFAULT_PARSER_OPTIONS.dateType, integerType = DEFAULT_PARSER_OPTIONS.integerType, unknownType = DEFAULT_PARSER_OPTIONS.unknownType, enumSuffix = DEFAULT_PARSER_OPTIONS.enumSuffix, emptySchemaType = unknownType || DEFAULT_PARSER_OPTIONS.emptySchemaType }) => ({
4680
+ setup: ({ validate = false, contentType, server, discriminator = "preserve", enums = "inline", pathParamsCasing, dateType = DEFAULT_PARSER_OPTIONS.dateType, integerType = DEFAULT_PARSER_OPTIONS.integerType, unknownType = DEFAULT_PARSER_OPTIONS.unknownType, enumSuffix = DEFAULT_PARSER_OPTIONS.enumSuffix, emptySchemaType = unknownType || DEFAULT_PARSER_OPTIONS.emptySchemaType }) => ({
4676
4681
  validate,
4677
4682
  contentType,
4678
4683
  server,