Swagger ui - Query param

19,370

Solution 1

You can use the annotation @ApiParam from the Swagger annotations in order to configure the Query param to be used from the Swagger-UI.

For example

@Path("/{username}")
@ApiOperation(value = "Updated user")
public Response updateUser(
  @ApiParam(value = "description for query-parameter") @QueryParam("username") String username
) {
...
}

Please, read more about this annotation in the following official documentation: https://github.com/swagger-api/swagger-core/wiki/Annotations#apiparam

Solution 2

You can't, but since swagger 2.0 (I don't know if this is supported by swagger-code/swagger-ui), you can defines parameters to be reuse across operations.

For example :

{
  "parameters": {
    "pageParam": {
      "name": "page",
      "in": "query",
      "description": "page number to get",
      "required": false,
      "type": "integer",
      "format": "int32"
    }
  },
  "paths": {
    "/customers": {
      "get":  {
        "description": "Retrive list of customers",
        "parameters": {
          "$ref": "#/parameters/pageParam"
        },
        ...
      }
    }
  },
  ...
}
Share:
19,370
Jacaro
Author by

Jacaro

Updated on June 06, 2022

Comments

  • Jacaro
    Jacaro almost 2 years

    I am using Swagger ui and Swagger core (1.3) for a jersey application. I have certain query parameters which I must send with every request like post, get, delete...

    How can I default this ?

  • Jacaro
    Jacaro almost 9 years
    ApiParam for queryparam can be used only if the operation has such parameter in its definition. But, here I want to send a Query parameter with the url that will be accessed when a post or get or delete operation is tried out. Hope you understand what I am looking for
  • Jivan Pal
    Jivan Pal over 2 years
    In the scope of the function, check if the variable's value is null. If it is, that means the query parameter was not specified in the HTTP request. That is, you can do if (username == null) { username = "myDefaultValue"; }.