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(
1414) : Promise < Filesystem < OpenAPIV3xDocument > > {
1515 const { value, rootURL, trust } = input ;
1616 const specification = trust
17- ? trustedValidate ( { value, rootURL } )
17+ ? await trustedValidate ( { value, rootURL } )
1818 : await untrustedValidate ( { value, rootURL } ) ;
1919
2020 const filesystem = await createFileSystem ( { value : specification , rootURL } ) ;
@@ -54,17 +54,15 @@ async function untrustedValidate(input: ValidateOpenAPIV3Input) {
5454 * It assumes the specification is already a valid specification.
5555 * It's faster than `untrustedValidate`.
5656 */
57- function trustedValidate ( input : ValidateOpenAPIV3Input ) {
57+ async function trustedValidate ( input : ValidateOpenAPIV3Input ) {
5858 const { value, rootURL } = input ;
5959 const result = ( ( ) => {
6060 if ( typeof value === 'string' ) {
6161 try {
6262 return JSON . parse ( value ) ;
6363 } 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 ) ;
6866 }
6967 }
7068 return value ;
You can’t perform that action at this time.
0 commit comments