Skip to content

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

@s101d1

Description

@s101d1

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) {
    ...
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions