Skip to content

Commit d00dc8c

Browse files
authored
Pass spec validation errors through OpenAPIParseError (#3240)
1 parent 2c85a30 commit d00dc8c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

.changeset/four-jobs-reply.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/openapi-parser': patch
3+
---
4+
5+
Pass scalar's errors through OpenAPIParseError

packages/openapi-parser/src/error.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ErrorObject } from '@scalar/openapi-parser';
2+
13
type OpenAPIParseErrorCode =
24
| 'invalid'
35
| 'parse-v2-in-v3'
@@ -12,17 +14,19 @@ export class OpenAPIParseError extends Error {
1214
public override name = 'OpenAPIParseError';
1315
public code: OpenAPIParseErrorCode;
1416
public rootURL: string | null;
15-
17+
public errors: ErrorObject[] | undefined;
1618
constructor(
1719
message: string,
1820
options: {
1921
code: OpenAPIParseErrorCode;
2022
rootURL?: string | null;
2123
cause?: Error;
24+
errors?: ErrorObject[] | undefined;
2225
}
2326
) {
2427
super(message, { cause: options.cause });
2528
this.code = options.code;
2629
this.rootURL = options.rootURL ?? null;
30+
this.errors = options.errors;
2731
}
2832
}

packages/openapi-parser/src/v3.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ async function untrustedValidate(input: ValidateOpenAPIV3Input) {
4040
throw new OpenAPIParseError('Invalid OpenAPI document', {
4141
code: 'invalid',
4242
rootURL,
43+
errors: result.errors,
4344
});
4445
}
4546

0 commit comments

Comments
 (0)