-
Notifications
You must be signed in to change notification settings - Fork 535
Open
Labels
Description
Description
When a valid OpenAPI YAML document starts with an opening curly brace {
, parsing returns a result with a null OpenAPI and error messages. This affects Swagger 2.0 and OpenAPI 3.0/3.1.
The error is caused by the parser checking to see if the first non-whitespace character of the document is a {
and, if it is, assuming the rest of the document is valid JSON and using a JSON specific deserialiser.
Affected Version
2.1.33
Steps to Reproduce
The error can be reproduced by running the following Java code
import io.swagger.parser.OpenAPIParser;
import io.swagger.v3.parser.core.models.ParseOptions;
import io.swagger.v3.parser.core.models.SwaggerParseResult;
import java.util.List;
class Parse {
public static void main(String[] args) {
String doc = """
{
openapi: "2.0.0",
"info": {
"title": "Test API spec",
"version": "1.0.0"
},
"paths": {}
}
""";
var parser = new OpenAPIParser();
SwaggerParseResult result = parser.readContents(doc, List.of(), new ParseOptions());
assert result.getOpenAPI() != null;
assert result.getMessages().isEmpty();
}
}
Expected Behavior
The assertions in the provided code example succeed.
Actual Behavior
The assertions in the provided code example fail.
Environment
- Java version: Corretto 17
- Build tool: 8.14
- OS: macOS Sequoia 15.6.1
Checklist
- I have searched the existing issues and this is not a duplicate.
- I have provided sufficient information for maintainers to reproduce the issue.