Skip to content

Commit

Permalink
Merge pull request #1410 from kerrykimbrough/issue-1409
Browse files Browse the repository at this point in the history
When parameter style is invalid, return a helpful message instead of throwing an NPE
  • Loading branch information
gracekarina authored Aug 1, 2020
2 parents 93676f0 + 931c00b commit 4cf798f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ public Parameter getParameter(ObjectNode obj, String location, ParseResult resul
Boolean explode = getBoolean("explode", obj, false, location, result);
if (explode != null) {
parameter.setExplode(explode);
} else if(parameter.getStyle().equals(StyleEnum.FORM)){
} else if(StyleEnum.FORM.equals(parameter.getStyle())){
parameter.setExplode(Boolean.TRUE);
} else {
parameter.setExplode(Boolean.FALSE);
Expand Down Expand Up @@ -2674,7 +2674,7 @@ public void setStyle(String value, Parameter parameter, String location, ObjectN
} else if (value.equals(Parameter.StyleEnum.SPACEDELIMITED.toString())) {
parameter.setStyle(Parameter.StyleEnum.SPACEDELIMITED);
} else {
result.invalidType(location, "style", "string", obj);
result.invalidType(location, "style", "StyleEnum", obj);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,56 @@ public void testDeserializeByteString() {
"attribute components.schemas.ByteString.default=`W.T.F?` is not of type `byte`"));
}

@Test
public void testStyleInvalid() {
String json =
"{"
+ " \"openapi\": \"3.0.0\","
+ " \"info\": {"
+ " \"title\": \"realize\","
+ " \"version\": \"0.0.0\""
+ " },"
+ " \"paths\": {"
+ " \"/realize/{param}\": {"
+ " \"post\": {"
+ " \"parameters\": ["
+ " {"
+ " \"name\": \"param\","
+ " \"in\": \"path\","
+ ""
+ " \"style\": \"DERP\","
+ " \"required\": true,"
+ ""
+ " \"schema\": {"
+ " \"type\": \"string\","
+ " \"nullable\": false,"
+ " \"minLength\": 1"
+ " }"
+ " }"
+ " ],"
+ " \"responses\": {"
+ " \"200\": {"
+ " \"description\": \"Success\","
+ " \"content\": {"
+ " \"application/json\": {"
+ " \"schema\": {"
+ " \"type\": \"object\""
+ " }"
+ " }"
+ " }"
+ " }"
+ " }"
+ " }"
+ " }"
+ " }"
+ "}"
;
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(json, null, null);
assertTrue(result.getMessages().size() == 1);
assertEquals(result.getMessages().get(0), "attribute paths.'/realize/{param}'(post).parameters.[param].style is not of type `StyleEnum`");
}

@Test
public void testDeserializeWithMessages() {
String yaml = "openapi: '3.0.0'\n" +
Expand Down

0 comments on commit 4cf798f

Please sign in to comment.