question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Suggestion] New parameter on @ApiParam to specify parameter type

See original GitHub issue

I have a GET action method like this in dropwizard framework:

  @Path("/{id}")
  @GET
  public Response getFoo(@ApiParam(value = "Foo Id", required = true) @PathParam("id") IntParam id) {
    ...
  }

IntParam is a dropwizard helper class that encapsulates the parameter type parser, so if user provides a value that can’t be converted to integer for the id, Bad Request (400) response will be returned.

The problem by using this IntParam class is swagger will generate the parameter type in swagger.json as a string rather than integer since IntParam class is not understandable by the swagger parser.

        "parameters" : [ {
          "name" : "id",
          "in" : "path",
          "description" : "Foo Id",
          "required" : true,
          "type" : "string"
        } ],

I could change the type of id to int/Integer in the action method but I will lose the benefit of IntParam.

So my suggestion is to add new parameter for @ApiParam that let developer to set or override the parameter type, maybe something like dataType parameter in @ApiImplicitParam.

  @Path("/{id}")
  @GET
  public Response getFoo(@ApiParam(value = "Foo Id", required = true, dataType = "int") @PathParam("id") IntParam id) {
    ...
  }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
s101d1commented, Jan 18, 2017

Thanks. The documentation needs to be improved, like the explanation of the type field should provide the list of possible values. When I tried the type, I have to guess what is the correct value for the integer parameter. I tried set it to "Integer" at first, it didn’t work, then tried "int", it didn’t work too, then finally got the correct value which is "integer" (all lower case).

0reactions
webroncommented, Jan 18, 2017

PRs are welcome.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make SpringFox Swagger render a string parameter ...
Try to override String param as @ApiParam(hidden = true) and add new param for your object: @ApiImplicitParams({ @ApiImplicitParam(name ...
Read more >
Swagger @ApiParam vs @ApiModelProperty - Baeldung
The @ApiParam annotation helps to specify the name, type, description (value), and example value of the parameter. Moreover, we can specify ...
Read more >
Documenting and Trying Out Matrix Type Parameters
Has anyone tried documenting and then "trying out" matrix type parameters with Swagger? Documenting seems to be fine (apart from label not being...
Read more >
ApiParam (swagger-annotations 1.5.0 API)
Annotation Type ApiParam ... Specifies whether the parameter can accept multiple values by having ... Specifies if the parameter is required or not....
Read more >
Springfox Reference Documentation - GitHub Pages
Alternatively you could set the following gradle/project properties (-Pproperty) ... ParameterType; import springfox.documentation.service.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found