Skip to content

Commit 1478517

Browse files
authored
Merge pull request #1782 from swagger-api/issue1780
add fix for issue 1780 - Validation of the openapi version
2 parents 03733f8 + 7e59db0 commit 1478517

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/OpenAPIDeserializer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,11 @@ public OpenAPI parseRoot(JsonNode node, ParseResult result, String path) {
314314
} else if (value.startsWith("3.1")) {
315315
result.openapi31(true);
316316
}
317-
openAPI.setOpenapi(value);
317+
if (!value.startsWith("3.0.") && !value.startsWith("3.1.")){
318+
result.warning(location, "The provided definition does not specify a valid version field");
319+
}
320+
openAPI.setOpenapi(value);
321+
318322

319323
ObjectNode obj = getObject("info", rootNode, true, location, result);
320324
if (obj != null) {

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@ public class OpenAPIV3ParserTest {
8686
protected int serverPort = getDynamicPort();
8787
protected WireMockServer wireMockServer;
8888

89+
@Test
90+
public void testIssue1780() {
91+
ParseOptions options = new ParseOptions();
92+
options.setInferSchemaType(false);
93+
String defaultSchemaType = "---\n" +
94+
"openapi: '3.0'\n" +
95+
"info:\n" +
96+
" description: This is a credit card account service tier 3 microservice\n" +
97+
" title: SC-CCS-CCSRV_AC Credit Card Account Service\n" +
98+
" version: 1.0.0\n" +
99+
"tags:\n" +
100+
"- name: creditCardAccount\n" +
101+
" description: Credit Card Accounts\n" +
102+
"paths: {}\n" +
103+
"x-ibm-configuration: {}";
104+
SwaggerParseResult result = new OpenAPIV3Parser().readContents(defaultSchemaType, null, options);
105+
OpenAPI openAPI = result.getOpenAPI();
106+
assertNotNull(openAPI);
107+
assertTrue(result.getMessages().contains("The provided definition does not specify a valid version field"));
108+
109+
}
110+
89111
@Test
90112
public void testIssue1758() throws Exception{
91113
ParseOptions options = new ParseOptions();

0 commit comments

Comments
 (0)