mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Pass spec validation errors through OpenAPIParseError (#3240)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@gitbook/openapi-parser': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Pass scalar's errors through OpenAPIParseError
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { ErrorObject } from '@scalar/openapi-parser';
|
||||||
|
|
||||||
type OpenAPIParseErrorCode =
|
type OpenAPIParseErrorCode =
|
||||||
| 'invalid'
|
| 'invalid'
|
||||||
| 'parse-v2-in-v3'
|
| 'parse-v2-in-v3'
|
||||||
@@ -12,17 +14,19 @@ export class OpenAPIParseError extends Error {
|
|||||||
public override name = 'OpenAPIParseError';
|
public override name = 'OpenAPIParseError';
|
||||||
public code: OpenAPIParseErrorCode;
|
public code: OpenAPIParseErrorCode;
|
||||||
public rootURL: string | null;
|
public rootURL: string | null;
|
||||||
|
public errors: ErrorObject[] | undefined;
|
||||||
constructor(
|
constructor(
|
||||||
message: string,
|
message: string,
|
||||||
options: {
|
options: {
|
||||||
code: OpenAPIParseErrorCode;
|
code: OpenAPIParseErrorCode;
|
||||||
rootURL?: string | null;
|
rootURL?: string | null;
|
||||||
cause?: Error;
|
cause?: Error;
|
||||||
|
errors?: ErrorObject[] | undefined;
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
super(message, { cause: options.cause });
|
super(message, { cause: options.cause });
|
||||||
this.code = options.code;
|
this.code = options.code;
|
||||||
this.rootURL = options.rootURL ?? null;
|
this.rootURL = options.rootURL ?? null;
|
||||||
|
this.errors = options.errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ async function untrustedValidate(input: ValidateOpenAPIV3Input) {
|
|||||||
throw new OpenAPIParseError('Invalid OpenAPI document', {
|
throw new OpenAPIParseError('Invalid OpenAPI document', {
|
||||||
code: 'invalid',
|
code: 'invalid',
|
||||||
rootURL,
|
rootURL,
|
||||||
|
errors: result.errors,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user