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

@ApiParam not working on Interface method declarations #388

Closed
charlesakalugwu opened this issue Aug 6, 2014 · 18 comments
Closed

@ApiParam not working on Interface method declarations #388

charlesakalugwu opened this issue Aug 6, 2014 · 18 comments
Labels
Milestone

Comments

@charlesakalugwu
Copy link

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

@dilipkrish
Copy link
Member

@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 dilipkrish added the bug label Aug 6, 2014
@charlesakalugwu
Copy link
Author

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

@fgaule
Copy link
Contributor

fgaule commented Aug 13, 2014

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

@dilipkrish dilipkrish added feature and removed bug labels Aug 18, 2014
@dilipkrish
Copy link
Member

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

@batcer
Copy link

batcer commented Sep 8, 2015

@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
Copy link

batcer commented Sep 11, 2015

Emmmm so what? :)

@joethaw
Copy link

joethaw commented Feb 6, 2016

It does not work for me either in 2.3.1.

@toddcscar
Copy link

Any timeline for fixing this?

@grined
Copy link

grined commented Oct 25, 2016

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

@dilipkrish
Copy link
Member

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

@flowerrrr
Copy link

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

@dilipkrish
Copy link
Member

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

@abryantsev
Copy link

abryantsev commented Nov 18, 2016

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.

@dilipkrish
Copy link
Member

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

@swatisacheti
Copy link

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

@piyushj90
Copy link

piyushj90 commented Feb 8, 2018

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

@shentuzhigang
Copy link

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

@shentuzhigang
Copy link

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

sorry ,i find i use error DocumentationType of docket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests