Pass spec validation errors through OpenAPIParseError (#3240)

This commit is contained in:
Nolann B.
2025-05-18 13:20:17 +02:00
committed by GitHub
parent 2c85a302fc
commit d00dc8ca72
3 changed files with 11 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@gitbook/openapi-parser': patch
---
Pass scalar's errors through OpenAPIParseError
+5 -1
View File
@@ -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;
}
}
+1
View File
@@ -40,6 +40,7 @@ async function untrustedValidate(input: ValidateOpenAPIV3Input) {
throw new OpenAPIParseError('Invalid OpenAPI document', {
code: 'invalid',
rootURL,
errors: result.errors,
});
}