Skip to content

Commit 7fefe49

Browse files
authored
Catch OpenAPI validation errors (#3602)
1 parent 729921f commit 7fefe49

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changeset/happy-vans-work.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+
Catch OpenAPI validation errors

packages/openapi-parser/src/v3.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ import type { ParseOpenAPIInput, ParseOpenAPIResult } from './parse';
1010
*/
1111
export async function parseOpenAPIV3(input: ParseOpenAPIInput): Promise<ParseOpenAPIResult> {
1212
const { value, rootURL, options = {} } = input;
13-
const result = await validate(value);
13+
14+
const result = await validate(value).catch((error) => {
15+
throw new OpenAPIParseError('Invalid OpenAPI document', {
16+
code: 'invalid',
17+
rootURL,
18+
cause: error,
19+
});
20+
});
1421

1522
// If there is no version, we consider it invalid instantely.
1623
if (!result.version) {

0 commit comments

Comments
 (0)