Skip to content
Documentation
jsdoc-open-api
short
Describing Parameters

Describing Parameters

Describing Parameters

Parameters are defined with @pathParam, @queryParam, @headerParam, @cookieParam or @paramComponent. To describe a parameter, you specify its data type, name, and description. To denote a parameter as optional, enclose its name in square brackets [ ]. Here is an example:


_10
/**
_10
* GET /users/{userId}
_10
* @summary Get a user by ID.
_10
* @pathParam {integer} userId - Numeric ID of the user to get.
_10
* @queryParam {boolean} [verbose] - Return all user information.
_10
*/

Parameter types

OpenAPI 3.0 distinguishes between the following parameter types based on the parameter location.

Parameter parameters

Path parameters are variable parts of a URL path. They are typically used to point to a specific resource within a collection, such as a user identified by ID. A URL can have several path parameters, each denoted with curly braces { }.


_10
GET /users/{id}
_10
GET /cars/{carId}/drivers/{driverId}
_10
GET /report.{format}

Each path parameter must be substituted with an actual value when the client makes an API call. In OpenAPI, a path parameter is defined using @pathParam. The parameter name must be the same as specified in the path. Also remember path parameters are always required. For example, the /users/{id} endpoint would be described as:


_10
/**
_10
* GET /users/{id}
_10
* @summary Get a user by ID.
_10
* @pathParam {integer} id - The user ID
_10
*/

Query parameters

Query parameters are the most common type of parameters. They appear at the end of the request URL after a question mark (?), with different name=value pairs separated by ampersands (&). Query parameters can be required and optional.

Use @queryParam to denote query parameters:


_10
/**
_10
* @queryParam {integer} [offset] - The number of items to skip before starting to collect the result set
_10
* @queryParam {integer} [limit] - The numbers of items to return
_10
*/

Note: To describe API keys passed as query parameters, use securitySchemes and security instead. See Authentication.

Header parameters

An API call may require that custom headers be sent with an HTTP request. OpenAPI lets you define custom request headers with @headerParam. For example, suppose, a call to GET /ping requires the X-Request-ID header:


_10
GET /ping HTTP/1.1
_10
Host: example.com
_10
X-Request-ID: 77e1c83b-7bb0-437b-bc50-a7a58e5660ac

You would define this operation as follows:


_10
/**
_10
* GET /ping
_10
* @summary Checks if the server is alive
_10
* @headerParam {string} X-Request-ID
_10
*/

Note: Header parameters named Accept, Content-Type and Authorization are not allowed.

Cookie parameters

Operations can also pass parameters in the Cookie header, as Cookie: name=value. Multiple cookie parameters are sent in the same header, separated by a semicolon, and space.


_10
GET /api/users
_10
Host: example.com
_10
Cookie: debug=0; csrftoken=BUSe35dohU3O1MZvDCUOJ

Use @cookieParam to define cookie parameters:


_10
/**
_10
* @cookieParam {integer} [debug]
_10
* @cookieParam {string} [csrftoken]
_10
*/

Note: To define cookie authentication, use securitySchemes and security instead. See Authentication.

Required and optional parameters

By default, all request parameters are treated as required. You can enclose the parameter’s name in square brackets [ ] to mark it as optional. Path parameters are always required.

Default parameter values

Append =value to the variable name to specify the default value for an optional parameter. The default value is the one that the server uses if the client does not supply the parameter value in the request. The value type must be the same as the parameter’s data type. A typical example is paging parameters such as offset and limit:


_10
GET /users
_10
GET /users?offset=30&limit=10

Assuming offset defaults to 0 and limit defaults to 20, you would define these parameters as:


_10
/**
_10
* @queryParam {integer} [offset=0] - The number of items to skip before starting to collect the result set.
_10
* @queryParam {integer} [limit=20] - The number of items to return.
_10
*/

Enum parameters

You can restrict a parameter to a fixed set of values by adding the enum to the schema. The enum values must be of the same type as the parameter data type.


_10
/**
_10
* @queryParam {Status} [status]
_10
*/


_10
components:
_10
schemas:
_10
Status:
_10
type: string
_10
enum:
_10
- available
_10
- pending
_10
- sold

Reusable Parameters

Parameters can be defined in components to be reused elsewhere. The following parameter definition:


_12
components:
_12
parameters:
_12
ExampleParameter:
_12
in: query
_12
name: limit
_12
schema:
_12
type: integer
_12
minimum: 1
_12
maximum: 100
_12
default: 20
_12
required: false
_12
description: The number of items to return.

Can be used as:


_10
/**
_10
* @paramComponent {ExampleParameter}
_10
*/