Skip to content

Commit

Permalink
refs #2556 - updated logging for ApiImplicitParam with no datatype de…
Browse files Browse the repository at this point in the history
…fined
  • Loading branch information
frantuma committed Dec 7, 2017
1 parent 7642e88 commit d9801f7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import com.google.common.collect.Sets;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.type.TypeFactory;
Expand All @@ -27,6 +28,9 @@ public static Type typeFromString(String type) {
if (primitive != null) {
return primitive.getKeyClass();
}
if (StringUtils.isBlank(type)) {
return null;
}
try {
return loadClassByName(type);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,9 @@ protected Parameter readImplicitParam(ApiImplicitParam param) {
}
final Type type = param.dataTypeClass() == Void.class ? ReflectionUtils.typeFromString(param.dataType())
: param.dataTypeClass();
if (type == null) {
LOGGER.error("no dataType defined for implicit param `{}`! resolved parameter will not have a type defined, and will therefore be not compliant with spec. see https://github.com/swagger-api/swagger-core/issues/2556.", param.name());
}
return ParameterProcessor.applyAnnotations(swagger, p, (type == null) ? String.class : type,
Arrays.<Annotation>asList(param));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void scanImplicitParam() {
Swagger swagger = getSwagger(ResourceWithImplicitParams.class);
List<Parameter> params = swagger.getPath("/testString").getPost().getParameters();
assertNotNull(params);
assertEquals(params.size(), 7);
assertEquals(params.size(), 8);

assertEquals(params.get(0).getName(), "sort");
assertEquals(params.get(0).getIn(), "query");
Expand Down Expand Up @@ -262,6 +262,13 @@ public void scanImplicitParam() {
assertEquals(bodyParam.getName(), "body");
assertEquals(bodyParam.getIn(), "body");
assertTrue(bodyParam.getRequired());

queryParam = (QueryParameter) params.get(7);
assertEquals(queryParam.getName(), "description");
assertEquals(queryParam.getIn(), "query");
// see https://github.com/swagger-api/swagger-core/issues/2556. should be not null
assertNull(queryParam.getType());

}

@Test(description = "scan implicit params with file objct")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class ResourceWithImplicitParams {
@ApiImplicitParam(name = "width", paramType = "formData", dataType = "int", allowableValues = "range[infinity,1]"),
@ApiImplicitParam(name = "height", paramType = "query", dataType = "int", allowableValues = "range[3,4]"),
@ApiImplicitParam(name = "body", paramType = "body", dataType = "string", required = true),
@ApiImplicitParam(name = "width", paramType = "unknown")
@ApiImplicitParam(name = "width", paramType = "unknown"),
@ApiImplicitParam(name = "description", paramType = "query")
})
@ApiOperation("Test operation with implicit parameters")
public void testString() {
Expand Down

0 comments on commit d9801f7

Please sign in to comment.