Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger ui - Query param

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 ?

like image 720
Jacaro Avatar asked Jul 01 '15 19:07

Jacaro


People also ask

What is a query param?

Query parameters are a defined set of parameters attached to the end of a url. They are extensions of the URL that are used to help define specific content or actions based on the data being passed. To append query params to the end of a URL, a '? ' Is added followed immediately by a query parameter.

How do you pass NULL values in Swagger?

In JSON there are two ways to represent null values, first is when there is no value for a given key and its value is implicitly set to null, and second is when the key is present and its value is explicitly set to null.

Are query parameters optional?

As query parameters are not a fixed part of a path, they can be optional and can have default values.


2 Answers

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

like image 143
ipeluffo Avatar answered Sep 22 '22 16:09

ipeluffo


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"
        },
        ...
      }
    }
  },
  ...
}
like image 43
Nelson G. Avatar answered Sep 18 '22 16:09

Nelson G.