springfox icon indicating copy to clipboard operation
springfox copied to clipboard

@ApiParam not working on Interface method declarations

Open charlesakalugwu opened this issue 12 years ago • 18 comments

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

charlesakalugwu avatar Aug 06 '14 12:08 charlesakalugwu

@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?

dilipkrish avatar Aug 06 '14 16:08 dilipkrish

thanks for the tip @dilipkrish . I will give it a shot!

charlesakalugwu avatar Aug 08 '14 08:08 charlesakalugwu

@charleslieferando are you working on this? May i be of your help?

fgaule avatar Aug 13 '14 14:08 fgaule

Changed this to a feature. Its a little harder to implement this

dilipkrish avatar Aug 18 '14 21:08 dilipkrish

@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?

batcer avatar Sep 08 '15 13:09 batcer

Emmmm so what? :)

batcer avatar Sep 11 '15 08:09 batcer

It does not work for me either in 2.3.1.

joethaw avatar Feb 06 '16 00:02 joethaw

Any timeline for fixing this?

toddcscar avatar Feb 10 '16 00:02 toddcscar

@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 avatar Oct 25 '16 10:10 grined

@grined The @ApiIgnore issue is fixed in 2.6.0. No need to do anything.

dilipkrish avatar Oct 25 '16 14:10 dilipkrish

After upgrading from 2.5.0 to 2.6.0 it seems that @ApiParam is ignored again if defined on interface methods.

flowerrrr avatar Nov 18 '16 14:11 flowerrrr

@flowerrrr thanks for reporting.. perhaps could you create a new issue with maybe a breaking test?

dilipkrish avatar Nov 18 '16 14:11 dilipkrish

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.

abryantsev avatar Nov 18 '16 17:11 abryantsev

@flowerrrr & @abryantsev thanks for reporting. I verified and created a new issue for this #1575

dilipkrish avatar Nov 21 '16 02:11 dilipkrish

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

swatisacheti avatar Sep 01 '17 01:09 swatisacheti

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

piyushj90 avatar Feb 08 '18 11:02 piyushj90

@dilipkrish我正在使用2.9.2版,仍然面临相同的问题。

shentuzhigang avatar Apr 13 '20 14:04 shentuzhigang

@dilipkrish我正在使用2.9.2版,仍然面临相同的问题。

sorry ,i find i use error DocumentationType of docket

shentuzhigang avatar Apr 13 '20 15:04 shentuzhigang