@kubb/adapter-oas 5.5.3 → 5.5.5
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 +22 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +22 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1203,9 +1203,9 @@ type ServerOptions = {
|
|
|
1203
1203
|
*/
|
|
1204
1204
|
type AdapterOasOptions = {
|
|
1205
1205
|
/**
|
|
1206
|
-
* Validate the OpenAPI spec with `@readme/openapi-parser` before parsing.
|
|
1207
|
-
*
|
|
1208
|
-
*
|
|
1206
|
+
* Validate the OpenAPI spec with `@readme/openapi-parser` before parsing. Each problem is
|
|
1207
|
+
* reported as a `KUBB_INVALID_SPEC` warning and generation continues. Set to `false` to skip the
|
|
1208
|
+
* check, which also makes generation faster on a large spec.
|
|
1209
1209
|
*
|
|
1210
1210
|
* @default true
|
|
1211
1211
|
*/
|
package/dist/index.js
CHANGED
|
@@ -429,7 +429,7 @@ async function resolveSource(sourcePath) {
|
|
|
429
429
|
* its parse error instead.
|
|
430
430
|
*/
|
|
431
431
|
async function assertInputExists(input) {
|
|
432
|
-
if (
|
|
432
|
+
if (urlRegExp.test(input)) return;
|
|
433
433
|
if (!await exists(input)) throw new Diagnostics.Error({
|
|
434
434
|
code: Diagnostics.code.inputNotFound,
|
|
435
435
|
severity: "error",
|
|
@@ -518,7 +518,7 @@ async function parseDocument(pathOrApi) {
|
|
|
518
518
|
*/
|
|
519
519
|
async function parseFromConfig(source) {
|
|
520
520
|
if (source.type === "data") return parseDocument(typeof source.data === "string" ? parse(source.data) : structuredClone(source.data));
|
|
521
|
-
if (
|
|
521
|
+
if (urlRegExp.test(source.path)) return parseDocument(source.path);
|
|
522
522
|
const resolved = path.resolve(path.dirname(source.path), source.path);
|
|
523
523
|
await assertInputExists(resolved);
|
|
524
524
|
return parseDocument(resolved);
|
|
@@ -541,8 +541,17 @@ function assertDocument(document) {
|
|
|
541
541
|
location: { kind: "config" }
|
|
542
542
|
});
|
|
543
543
|
}
|
|
544
|
+
/** Reports a validation problem as a `KUBB_INVALID_SPEC` warning, a no-op outside a build. */
|
|
545
|
+
function reportInvalidSpec(message) {
|
|
546
|
+
Diagnostics.report({
|
|
547
|
+
code: Diagnostics.code.invalidSpec,
|
|
548
|
+
severity: "warning",
|
|
549
|
+
message,
|
|
550
|
+
help: "Fix the spec, or run `kubb validate` to list every error. Set `validate: false` on the adapter to skip this check."
|
|
551
|
+
});
|
|
552
|
+
}
|
|
544
553
|
/**
|
|
545
|
-
* Validates an OpenAPI document using `@readme/openapi-parser
|
|
554
|
+
* Validates an OpenAPI document using `@readme/openapi-parser`. Throws with `throwOnError`, otherwise warns.
|
|
546
555
|
*
|
|
547
556
|
* @example
|
|
548
557
|
* ```ts
|
|
@@ -551,12 +560,18 @@ function assertDocument(document) {
|
|
|
551
560
|
*/
|
|
552
561
|
async function validateDocument(document, { throwOnError = false } = {}) {
|
|
553
562
|
const { compileErrors, validate } = await import("@readme/openapi-parser");
|
|
563
|
+
let result;
|
|
554
564
|
try {
|
|
555
|
-
|
|
556
|
-
if (!result.valid) throw new Error(compileErrors(result));
|
|
565
|
+
result = await validate(structuredClone(document), { validate: { errors: { colorize: throwOnError } } });
|
|
557
566
|
} catch (error) {
|
|
558
567
|
if (throwOnError) throw error;
|
|
568
|
+
reportInvalidSpec(getErrorMessage(error));
|
|
569
|
+
return;
|
|
559
570
|
}
|
|
571
|
+
if (result.valid) return;
|
|
572
|
+
if (throwOnError) throw new Error(compileErrors(result));
|
|
573
|
+
for (const { message } of result.errors) reportInvalidSpec(message.replace(/\n.*/s, ""));
|
|
574
|
+
if (result.additionalErrors > 0) reportInvalidSpec(`${result.additionalErrors} more validation errors are not listed.`);
|
|
560
575
|
}
|
|
561
576
|
//#endregion
|
|
562
577
|
//#region src/oas.ts
|
|
@@ -1978,7 +1993,7 @@ function walkPointer(document, $ref) {
|
|
|
1978
1993
|
applicable: false,
|
|
1979
1994
|
value: null
|
|
1980
1995
|
};
|
|
1981
|
-
const pointer =
|
|
1996
|
+
const pointer = trimmed.substring(1);
|
|
1982
1997
|
let docCache = _refCache.get(document);
|
|
1983
1998
|
if (!docCache) {
|
|
1984
1999
|
docCache = /* @__PURE__ */ new Map();
|
|
@@ -1988,7 +2003,7 @@ function walkPointer(document, $ref) {
|
|
|
1988
2003
|
applicable: true,
|
|
1989
2004
|
value: docCache.get(pointer)
|
|
1990
2005
|
};
|
|
1991
|
-
const current = pointer.split("/").filter(Boolean).reduce((obj, key) => obj?.[key], document);
|
|
2006
|
+
const current = pointer.split("/").filter(Boolean).map((token) => globalThis.decodeURIComponent(token).replaceAll("~1", "/").replaceAll("~0", "~")).reduce((obj, key) => obj?.[key], document);
|
|
1992
2007
|
if (current) docCache.set(pointer, current);
|
|
1993
2008
|
return {
|
|
1994
2009
|
applicable: true,
|