@ApiParam not working on Interface method declarations
Hi guys,
first of all, many thanks for this library. It is an awesome piece of work.
I am having issues with the way @ApiParam is handled by swagger-springmvc (using 0.8.6-SNAPSHOT). My team has decided to add all swagger annotations to an interface which the Controller concrete class implements. When I have something like the following:
@Api(value = "Guidelines", description="Describes the guidelines for annotating controller classes for swagger documentation discovery",
protocols="http", consumes=MediaType.APPLICATION_JSON_VALUE, produces=MediaType.APPLICATION_JSON_VALUE)
public interface IDocGuidelinesResource {
@ApiOperation(value = "Make a GET request to create a new documentation guideline", notes="Make a GET request to create a new documentation guideline")
@ApiResponses(value={
@ApiResponse(code = 200, message = "The documentation could be found"),
@ApiResponse(code = 404, message = "The documentation could not be found")
})
public Integer getCountBy2(@ApiParam(name="number", value="A number to multiply", required=true) Integer number, final HttpServletRequest request) throws Throwable;
@ApiOperation(value = "Make a GET request to retrieve new documentation guidelines", notes="Make a GET request to retrieve new documentation guidelines")
@ApiResponses(value={
@ApiResponse(code = 200, message = "The documentation could be found"),
@ApiResponse(code = 404, message = "The documentation could not be found")
})
public GuidelinesDto getGuidelines(@ApiParam(name="id", value="The id of the documentation", required=true) Integer id, final HttpServletRequest request) throws Throwable;
}
@Controller
@RequestMapping(value = "/guidelines", consumes="application/json; charset=UTF-8", produces="application/json; charset=UTF-8")
public class DocGuidelinesResource implements IDocGuidelinesResource {
@ResponseBody
@RequestMapping(value = "/multiply/{number}", method = RequestMethod.GET)
public Integer getCountBy2(@PathVariable("number") final Integer number, HttpServletRequest request) throws Throwable {
return number * 2;
}
@ResponseBody
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public GuidelinesDto getGuidelines(@PathVariable("id") Integer id, HttpServletRequest request) throws Throwable {
GuidelinesDto dto = new GuidelinesDto();
dto.setDescription("foo");
dto.setTitle("bar");
return dto;
}
}
the description of the method parameters as specified by @ApiParam is ignored as shown in the screenshot below:

But when I move @ApiParam back to the Controller concrete class (in one of the methods), the descriptions (value property of the @ApiParam annotation) show up properly as shown below:
....
@ResponseBody
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public GuidelinesDto getGuidelines(@ApiParam(name="id", value="The id of the documentation", required=true) @PathVariable("id") Integer id, HttpServletRequest request) throws Throwable {
GuidelinesDto dto = new GuidelinesDto();
dto.setDescription("foo");
dto.setTitle("bar");
return dto;
}
....

The problem is that we would really like to keep our Controller classes clean (without any swagger annotations). Do you have some pointers on what I can customize in swagger-springmvc to achieve the effect that the @ApiParam descriptions show up on the swagger UI? Any help or insights would be appreciated.
Best regards, Charles
@charleslieferando you're right it doesnt walk the object graph to find the parameter. if you'd like to take a crack at it, it needs to use AnnotationUtils to do the job? would you like to submit a PR?
thanks for the tip @dilipkrish . I will give it a shot!
@charleslieferando are you working on this? May i be of your help?
Changed this to a feature. Its a little harder to implement this
@dilipkrish Does not work for me in 2.2.2. Descriptions of method parameters by @ApiParam in interface are ignored. If annotations are moved to implementation class, they work. Should I open a bug report?
Emmmm so what? :)
It does not work for me either in 2.3.1.
Any timeline for fixing this?
@dilipkrish Should @ApiIgnore works in 2.5.0 in the same way? Now I still have a problem with it. I have added @ApiIgnore to a method parameter in an interface, but it is not ignored until I will add it to class. P.S. I have added .ignoredParameterTypes(ApiIgnore.class) to Docket.
@grined The @ApiIgnore issue is fixed in 2.6.0. No need to do anything.
After upgrading from 2.5.0 to 2.6.0 it seems that @ApiParam is ignored again if defined on interface methods.
@flowerrrr thanks for reporting.. perhaps could you create a new issue with maybe a breaking test?
Hi! For me @ApiParam doesn't work as well in the version 2.6.1. This is the first version in which I have tried to move swagger annotations out to the interface.
@flowerrrr & @abryantsev thanks for reporting. I verified and created a new issue for this #1575
Has this been fixed? The API doc still does not display descriptions of method parameters defined by @apiparam in the interface. We're using version 2.7.0
@dilipkrish I am using version 2.8.0 and still facing same issue. I have also created a new ticket for it #2239
@dilipkrish我正在使用2.9.2版,仍然面临相同的问题。
@dilipkrish我正在使用2.9.2版,仍然面临相同的问题。
sorry ,i find i use error DocumentationType of docket