springfox: @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:

image

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;
}

....

image

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

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 18 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@dilipkrish I am using version 2.8.0 and still facing same issue. I have also created a new ticket for it #2239