Fix OpenAPI v2 parsing (#3498)

This commit is contained in:
Greg Bergé
2025-07-23 17:21:05 +02:00
committed by GitHub
parent 2ba7e54c81
commit b5ad0ce1e5
4 changed files with 24 additions and 9 deletions
+7 -7
View File
@@ -35,6 +35,13 @@ async function untrustedValidate(input: ValidateOpenAPIV3Input) {
const { value, rootURL } = input;
const result = await validate(value);
if (result.version === '2.0') {
throw new OpenAPIParseError('Only OpenAPI v3 is supported', {
code: 'parse-v2-in-v3',
rootURL,
});
}
// Spec is invalid, we stop here.
if (!result.valid) {
throw new OpenAPIParseError('Invalid OpenAPI document', {
@@ -44,13 +51,6 @@ async function untrustedValidate(input: ValidateOpenAPIV3Input) {
});
}
if (result.version === '2.0') {
throw new OpenAPIParseError('Only OpenAPI v3 is supported', {
code: 'parse-v2-in-v3',
rootURL,
});
}
return result.specification;
}