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