Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When parameter style is invalid, return a helpful message instead of throwing an NPE #1410

Merged
merged 3 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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