File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed
packages/openapi-parser/src Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @gitbook/openapi-parser ' : patch
3
+ ---
4
+
5
+ Fallback to untrusted validation in case JSON spec is invalid
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export async function parseOpenAPIV3(
14
14
) : Promise < Filesystem < OpenAPIV3xDocument > > {
15
15
const { value, rootURL, trust } = input ;
16
16
const specification = trust
17
- ? trustedValidate ( { value, rootURL } )
17
+ ? await trustedValidate ( { value, rootURL } )
18
18
: await untrustedValidate ( { value, rootURL } ) ;
19
19
20
20
const filesystem = await createFileSystem ( { value : specification , rootURL } ) ;
@@ -54,17 +54,15 @@ async function untrustedValidate(input: ValidateOpenAPIV3Input) {
54
54
* It assumes the specification is already a valid specification.
55
55
* It's faster than `untrustedValidate`.
56
56
*/
57
- function trustedValidate ( input : ValidateOpenAPIV3Input ) {
57
+ async function trustedValidate ( input : ValidateOpenAPIV3Input ) {
58
58
const { value, rootURL } = input ;
59
59
const result = ( ( ) => {
60
60
if ( typeof value === 'string' ) {
61
61
try {
62
62
return JSON . parse ( value ) ;
63
63
} catch ( error ) {
64
- throw new OpenAPIParseError ( 'Invalid JSON' , {
65
- code : 'invalid' ,
66
- rootURL,
67
- } ) ;
64
+ /** In case of an invalid JSON, we fallback to untrusted validation. */
65
+ return untrustedValidate ( input ) ;
68
66
}
69
67
}
70
68
return value ;
You can’t perform that action at this time.
0 commit comments