@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.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
1
|
import { AdapterFactoryOptions, ast } from "@kubb/kit";
|
|
3
2
|
//#region ../../node_modules/.pnpm/@types+json-schema@7.0.15/node_modules/@types/json-schema/index.d.ts
|
|
4
3
|
// ==================================================================================================
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import { Diagnostics, ast, childName,
|
|
1
|
+
import { defineExtension } from "@kubb/core";
|
|
2
|
+
import { Diagnostics, ast, childName, enumPropName, extractRefName, macroDiscriminatorEnum, macroEnumName, macroSimplifyUnion, mergeAdjacentObjectsLazy } from "@kubb/kit";
|
|
3
3
|
import { access, readFile } from "node:fs/promises";
|
|
4
4
|
import { upgrade } from "@scalar/openapi-upgrader";
|
|
5
5
|
import { bundle } from "api-ref-bundler";
|
|
6
6
|
import { parse } from "yaml";
|
|
7
|
+
//#endregion
|
|
7
8
|
//#region kubb-extension.json
|
|
8
9
|
var compatibility = {
|
|
9
10
|
"kubb": ">=5.8.3",
|
|
@@ -11,7 +12,7 @@ var compatibility = {
|
|
|
11
12
|
};
|
|
12
13
|
//#endregion
|
|
13
14
|
//#region package.json
|
|
14
|
-
var version = "5.10.
|
|
15
|
+
var version = "5.10.3";
|
|
15
16
|
//#endregion
|
|
16
17
|
//#region src/constants.ts
|
|
17
18
|
/**
|
|
@@ -240,6 +241,20 @@ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
240
241
|
//#endregion
|
|
241
242
|
//#region ../../internals/utils/src/errors.ts
|
|
242
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
|
+
/**
|
|
243
258
|
* Extracts a human-readable message from any thrown value.
|
|
244
259
|
*
|
|
245
260
|
* @example
|
|
@@ -252,6 +267,20 @@ function getErrorMessage(value) {
|
|
|
252
267
|
return value instanceof Error ? value.message : String(value);
|
|
253
268
|
}
|
|
254
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
|
|
255
284
|
//#region ../../internals/utils/src/runtime.ts
|
|
256
285
|
const isBun = typeof Bun !== "undefined";
|
|
257
286
|
const isDeno = "Deno" in globalThis;
|
|
@@ -377,7 +406,28 @@ async function resolveSource(sourcePath) {
|
|
|
377
406
|
try {
|
|
378
407
|
return JSON.parse(data);
|
|
379
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 {
|
|
380
421
|
return parse(data);
|
|
422
|
+
} catch (error) {
|
|
423
|
+
throw new Diagnostics.Error({
|
|
424
|
+
code: 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
|
+
});
|
|
381
431
|
}
|
|
382
432
|
}
|
|
383
433
|
/**
|
|
@@ -462,11 +512,26 @@ async function bundleDocument(pathOrUrl) {
|
|
|
462
512
|
*/
|
|
463
513
|
async function parseFromConfig(source) {
|
|
464
514
|
const raw = await (async () => {
|
|
465
|
-
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);
|
|
466
519
|
await assertInputExists(source.path);
|
|
467
520
|
return bundleDocument(source.path);
|
|
468
521
|
})();
|
|
469
|
-
|
|
522
|
+
try {
|
|
523
|
+
return upgrade(raw, "3.1");
|
|
524
|
+
} catch (error) {
|
|
525
|
+
const declared = raw && typeof raw === "object" ? raw.openapi ?? raw.swagger : void 0;
|
|
526
|
+
throw new Diagnostics.Error({
|
|
527
|
+
code: 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
|
+
}
|
|
470
535
|
}
|
|
471
536
|
/**
|
|
472
537
|
* Asserts the parsed input is an OpenAPI or Swagger document.
|
|
@@ -477,7 +542,7 @@ async function parseFromConfig(source) {
|
|
|
477
542
|
* be a usable document, so it is fatal regardless of the `validate` option.
|
|
478
543
|
*/
|
|
479
544
|
function assertDocument(document) {
|
|
480
|
-
if (document && ("openapi" in document || "swagger" in document)) return;
|
|
545
|
+
if (document && typeof document === "object" && ("openapi" in document || "swagger" in document)) return;
|
|
481
546
|
throw new Diagnostics.Error({
|
|
482
547
|
code: Diagnostics.code.invalidDocument,
|
|
483
548
|
severity: "error",
|
|
@@ -514,7 +579,12 @@ async function validateDocument(document, { throwOnError = false } = {}) {
|
|
|
514
579
|
return;
|
|
515
580
|
}
|
|
516
581
|
if (result.valid) return;
|
|
517
|
-
if (throwOnError) throw new Error(
|
|
582
|
+
if (throwOnError) throw new Diagnostics.Error({
|
|
583
|
+
code: Diagnostics.code.invalidSpec,
|
|
584
|
+
severity: "error",
|
|
585
|
+
message: compileErrors(result),
|
|
586
|
+
help: "Fix each problem listed in the spec, then validate again."
|
|
587
|
+
});
|
|
518
588
|
for (const { message } of result.errors) reportInvalidSpec(message.replace(/\n.*/s, ""));
|
|
519
589
|
if (result.additionalErrors > 0) reportInvalidSpec(`${result.additionalErrors} more validation errors are not listed.`);
|
|
520
590
|
}
|
|
@@ -2188,13 +2258,6 @@ function createRefs(document) {
|
|
|
2188
2258
|
function scanSchema({ node, name }) {
|
|
2189
2259
|
visit(node, `#/components/schemas/${escapePointerToken(name)}`);
|
|
2190
2260
|
}
|
|
2191
|
-
/**
|
|
2192
|
-
* Escapes a single JSON pointer reference token per RFC 6901 (`~` → `~0`, `/` → `~1`), so a
|
|
2193
|
-
* property name with those characters maps to a distinct pointer instead of colliding in the dedupe.
|
|
2194
|
-
*/
|
|
2195
|
-
function escapePointerToken(token) {
|
|
2196
|
-
return token.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
2197
|
-
}
|
|
2198
2261
|
function visit(node, pointer) {
|
|
2199
2262
|
if (node.deprecated) Diagnostics.report({
|
|
2200
2263
|
code: Diagnostics.code.deprecated,
|