Skip to content

Commit ca1a014

Browse files
committed
improve AllowEmptyString option validation
1 parent d29f6f0 commit ca1a014

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,6 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul
15581558
return null;
15591559
}
15601560

1561-
15621561
Parameter parameter = null;
15631562

15641563
JsonNode ref = obj.get("$ref");
@@ -1589,11 +1588,10 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul
15891588

15901589
String value = getString("in", obj, true, location, result);
15911590

1592-
if (!result.isAllowEmptyStrings() && value == null) {
1591+
if (!result.isAllowEmptyStrings() && StringUtils.isBlank(value) || result.isAllowEmptyStrings() && value == null) {
15931592
return null;
15941593
}
15951594

1596-
15971595
if (QUERY_PARAMETER.equals(value)) {
15981596
parameter = new QueryParameter();
15991597
} else if (HEADER_PARAMETER.equals(value)) {
@@ -1609,7 +1607,6 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul
16091607
return null;
16101608
}
16111609

1612-
16131610
parameter.setIn(value);
16141611

16151612
value = getString("name", obj, true, location, result);

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,58 @@ public class OpenAPIV3ParserTest {
8383
protected int serverPort = getDynamicPort();
8484
protected WireMockServer wireMockServer;
8585

86+
@Test
87+
public void testIssue1644_NullValue() throws Exception{
88+
ParseOptions options = new ParseOptions();
89+
String issue1644 = "openapi: 3.0.0\n" +
90+
"info:\n" +
91+
" title: Operations\n" +
92+
" version: 0.0.0\n" +
93+
"paths:\n" +
94+
" \"/operations\":\n" +
95+
" post:\n" +
96+
" parameters:\n" +
97+
" - name: param0\n" +
98+
" schema:\n" +
99+
" type: string\n" +
100+
" responses:\n" +
101+
" default:\n" +
102+
" description: None\n";
103+
SwaggerParseResult result = new OpenAPIV3Parser().readContents(issue1644, null, options);
104+
105+
Assert.assertNotNull(result);
106+
Assert.assertNotNull(result.getOpenAPI());
107+
assertEquals(result.getMessages().size(),1);
108+
assertTrue(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].in is missing"));
109+
assertFalse(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].in is not of type `string`"));
110+
}
111+
112+
@Test
113+
public void testIssue1644_EmptyValue() throws Exception{
114+
ParseOptions options = new ParseOptions();
115+
String issue1644 = "openapi: 3.0.0\n" +
116+
"info:\n" +
117+
" title: Operations\n" +
118+
" version: 0.0.0\n" +
119+
"paths:\n" +
120+
" \"/operations\":\n" +
121+
" post:\n" +
122+
" parameters:\n" +
123+
" - name: param0\n" +
124+
" in: ''\n" +
125+
" schema:\n" +
126+
" type: string\n" +
127+
" responses:\n" +
128+
" default:\n" +
129+
" description: None\n";
130+
SwaggerParseResult result = new OpenAPIV3Parser().readContents(issue1644, null, options);
131+
132+
Assert.assertNotNull(result);
133+
Assert.assertNotNull(result.getOpenAPI());
134+
assertEquals(result.getMessages().size(),1);
135+
assertTrue(result.getMessages().contains("attribute paths.'/operations'(post).parameters.[param0].in is not of type `string`"));
136+
}
137+
86138

87139
@Test
88140
public void testEmptyStrings_False() throws Exception{

0 commit comments

Comments
 (0)