mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +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 =
|
||||
| 'invalid'
|
||||
| 'parse-v2-in-v3'
|
||||
@@ -12,17 +14,19 @@ export class OpenAPIParseError extends Error {
|
||||
public override name = 'OpenAPIParseError';
|
||||
public code: OpenAPIParseErrorCode;
|
||||
public rootURL: string | null;
|
||||
|
||||
public errors: ErrorObject[] | undefined;
|
||||
constructor(
|
||||
message: string,
|
||||
options: {
|
||||
code: OpenAPIParseErrorCode;
|
||||
rootURL?: string | null;
|
||||
cause?: Error;
|
||||
errors?: ErrorObject[] | undefined;
|
||||
}
|
||||
) {
|
||||
super(message, { cause: options.cause });
|
||||
this.code = options.code;
|
||||
this.rootURL = options.rootURL ?? null;
|
||||
this.errors = options.errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ async function untrustedValidate(input: ValidateOpenAPIV3Input) {
|
||||
throw new OpenAPIParseError('Invalid OpenAPI document', {
|
||||
code: 'invalid',
|
||||
rootURL,
|
||||
errors: result.errors,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user