@kubb/adapter-oas 5.10.0 → 5.10.2
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 +76 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +76 -13
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#endregion
|
|
3
|
+
let _kubb_core = require("@kubb/core");
|
|
3
4
|
let _kubb_kit = require("@kubb/kit");
|
|
4
5
|
let node_fs_promises = require("node:fs/promises");
|
|
5
6
|
let _scalar_openapi_upgrader = require("@scalar/openapi-upgrader");
|
|
@@ -12,7 +13,7 @@ var compatibility = {
|
|
|
12
13
|
};
|
|
13
14
|
//#endregion
|
|
14
15
|
//#region package.json
|
|
15
|
-
var version = "5.10.
|
|
16
|
+
var version = "5.10.2";
|
|
16
17
|
//#endregion
|
|
17
18
|
//#region src/constants.ts
|
|
18
19
|
/**
|
|
@@ -241,6 +242,20 @@ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
241
242
|
//#endregion
|
|
242
243
|
//#region ../../internals/utils/src/errors.ts
|
|
243
244
|
/**
|
|
245
|
+
* Coerces an unknown thrown value to an `Error` instance.
|
|
246
|
+
* Returns the value as-is when it is already an `Error`; otherwise wraps it with `String(value)`.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* try { ... } catch(err) {
|
|
251
|
+
* throw new Error('Build failed', { cause: toError(err) })
|
|
252
|
+
* }
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
function toError(value) {
|
|
256
|
+
return value instanceof Error ? value : new Error(String(value));
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
244
259
|
* Extracts a human-readable message from any thrown value.
|
|
245
260
|
*
|
|
246
261
|
* @example
|
|
@@ -253,6 +268,20 @@ function getErrorMessage(value) {
|
|
|
253
268
|
return value instanceof Error ? value.message : String(value);
|
|
254
269
|
}
|
|
255
270
|
//#endregion
|
|
271
|
+
//#region ../../internals/utils/src/jsonPointer.ts
|
|
272
|
+
/**
|
|
273
|
+
* Escapes a single JSON pointer reference token per RFC 6901 (`~` → `~0`, `/` → `~1`), so a
|
|
274
|
+
* name holding those characters maps to a distinct pointer.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* escapePointerToken('/pets/{id}') // '~1pets~1{id}'
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
function escapePointerToken(token) {
|
|
282
|
+
return token.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
256
285
|
//#region ../../internals/utils/src/runtime.ts
|
|
257
286
|
const isBun = typeof Bun !== "undefined";
|
|
258
287
|
const isDeno = "Deno" in globalThis;
|
|
@@ -378,7 +407,28 @@ async function resolveSource(sourcePath) {
|
|
|
378
407
|
try {
|
|
379
408
|
return JSON.parse(data);
|
|
380
409
|
} catch {
|
|
410
|
+
return parseYaml(data, {
|
|
411
|
+
origin: sourcePath,
|
|
412
|
+
help: "Fix the syntax at the reported line, or check that `input` points at the spec and not an HTML page."
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Parses a YAML (or JSON) spec. A syntax error throws `KUBB_INVALID_DOCUMENT` naming `origin`,
|
|
418
|
+
* with the parser message, which keeps the line and column.
|
|
419
|
+
*/
|
|
420
|
+
function parseYaml(data, { origin, help }) {
|
|
421
|
+
try {
|
|
381
422
|
return (0, yaml.parse)(data);
|
|
423
|
+
} catch (error) {
|
|
424
|
+
throw new _kubb_kit.Diagnostics.Error({
|
|
425
|
+
code: _kubb_kit.Diagnostics.code.invalidDocument,
|
|
426
|
+
severity: "error",
|
|
427
|
+
message: `Cannot parse ${origin} as JSON or YAML: ${getErrorMessage(error)}`,
|
|
428
|
+
help,
|
|
429
|
+
location: { kind: "config" },
|
|
430
|
+
cause: toError(error)
|
|
431
|
+
});
|
|
382
432
|
}
|
|
383
433
|
}
|
|
384
434
|
/**
|
|
@@ -463,11 +513,26 @@ async function bundleDocument(pathOrUrl) {
|
|
|
463
513
|
*/
|
|
464
514
|
async function parseFromConfig(source) {
|
|
465
515
|
const raw = await (async () => {
|
|
466
|
-
if (source.type === "data") return typeof source.data === "string" ? (
|
|
516
|
+
if (source.type === "data") return typeof source.data === "string" ? parseYaml(source.data, {
|
|
517
|
+
origin: "the inline `input` string",
|
|
518
|
+
help: "Fix the syntax at the reported line. Kubb reads `input` as an inline spec, not a file path, because it starts with `{`, `[`, `openapi:`, or `swagger:`, or spans several lines."
|
|
519
|
+
}) : structuredClone(source.data);
|
|
467
520
|
await assertInputExists(source.path);
|
|
468
521
|
return bundleDocument(source.path);
|
|
469
522
|
})();
|
|
470
|
-
|
|
523
|
+
try {
|
|
524
|
+
return (0, _scalar_openapi_upgrader.upgrade)(raw, "3.1");
|
|
525
|
+
} catch (error) {
|
|
526
|
+
const declared = raw && typeof raw === "object" ? raw.openapi ?? raw.swagger : void 0;
|
|
527
|
+
throw new _kubb_kit.Diagnostics.Error({
|
|
528
|
+
code: _kubb_kit.Diagnostics.code.invalidDocument,
|
|
529
|
+
severity: "error",
|
|
530
|
+
message: `Cannot upgrade the document${declared ? ` (version ${String(declared)})` : ""} to OpenAPI 3.1: ${getErrorMessage(error)}`,
|
|
531
|
+
help: "Kubb reads Swagger 2.0, OpenAPI 3.0, and OpenAPI 3.1. Set `swagger` or `openapi` to one of those versions, and fix the reported problem in the document.",
|
|
532
|
+
location: { kind: "config" },
|
|
533
|
+
cause: toError(error)
|
|
534
|
+
});
|
|
535
|
+
}
|
|
471
536
|
}
|
|
472
537
|
/**
|
|
473
538
|
* Asserts the parsed input is an OpenAPI or Swagger document.
|
|
@@ -478,7 +543,7 @@ async function parseFromConfig(source) {
|
|
|
478
543
|
* be a usable document, so it is fatal regardless of the `validate` option.
|
|
479
544
|
*/
|
|
480
545
|
function assertDocument(document) {
|
|
481
|
-
if (document && ("openapi" in document || "swagger" in document)) return;
|
|
546
|
+
if (document && typeof document === "object" && ("openapi" in document || "swagger" in document)) return;
|
|
482
547
|
throw new _kubb_kit.Diagnostics.Error({
|
|
483
548
|
code: _kubb_kit.Diagnostics.code.invalidDocument,
|
|
484
549
|
severity: "error",
|
|
@@ -515,7 +580,12 @@ async function validateDocument(document, { throwOnError = false } = {}) {
|
|
|
515
580
|
return;
|
|
516
581
|
}
|
|
517
582
|
if (result.valid) return;
|
|
518
|
-
if (throwOnError) throw new Error(
|
|
583
|
+
if (throwOnError) throw new _kubb_kit.Diagnostics.Error({
|
|
584
|
+
code: _kubb_kit.Diagnostics.code.invalidSpec,
|
|
585
|
+
severity: "error",
|
|
586
|
+
message: compileErrors(result),
|
|
587
|
+
help: "Fix each problem listed in the spec, then validate again."
|
|
588
|
+
});
|
|
519
589
|
for (const { message } of result.errors) reportInvalidSpec(message.replace(/\n.*/s, ""));
|
|
520
590
|
if (result.additionalErrors > 0) reportInvalidSpec(`${result.additionalErrors} more validation errors are not listed.`);
|
|
521
591
|
}
|
|
@@ -2189,13 +2259,6 @@ function createRefs(document) {
|
|
|
2189
2259
|
function scanSchema({ node, name }) {
|
|
2190
2260
|
visit(node, `#/components/schemas/${escapePointerToken(name)}`);
|
|
2191
2261
|
}
|
|
2192
|
-
/**
|
|
2193
|
-
* Escapes a single JSON pointer reference token per RFC 6901 (`~` → `~0`, `/` → `~1`), so a
|
|
2194
|
-
* property name with those characters maps to a distinct pointer instead of colliding in the dedupe.
|
|
2195
|
-
*/
|
|
2196
|
-
function escapePointerToken(token) {
|
|
2197
|
-
return token.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
2198
|
-
}
|
|
2199
2262
|
function visit(node, pointer) {
|
|
2200
2263
|
if (node.deprecated) _kubb_kit.Diagnostics.report({
|
|
2201
2264
|
code: _kubb_kit.Diagnostics.code.deprecated,
|
|
@@ -2264,7 +2327,7 @@ const adapterOasName = "oas";
|
|
|
2264
2327
|
* })
|
|
2265
2328
|
* ```
|
|
2266
2329
|
*/
|
|
2267
|
-
const adapterOas = (0,
|
|
2330
|
+
const adapterOas = (0, _kubb_core.defineExtension)({
|
|
2268
2331
|
kind: "adapter",
|
|
2269
2332
|
meta: {
|
|
2270
2333
|
name: "oas",
|