On https://swagger.io/docs/specification/describing-parameters/ (OAS3) there is an example for common parameters which can be refered by $ref in paths and operations:
components:
parameters:
offsetParam: # <-- Arbitrary name for the definition that will be used to refer to it.
# Not necessarily the same as the parameter name.
in: query
name: offset
required: false
schema:
type: integer
minimum: 0
description: The number of items to skip before starting to collect the result set.
limitParam:
in: query
name: limit
required: false
schema:
type: integer
minimum: 1
maximum: 50
default: 20
description: The numbers of items to return.
paths:
/users:
get:
summary: Gets a list of users.
parameters:
- $ref: '#/components/parameters/offsetParam'
- $ref: '#/components/parameters/limitParam'
responses:
'200':
description: OK
/teams:
get:
summary: Gets a list of teams.
parameters:
- $ref: '#/components/parameters/offsetParam'
- $ref: '#/components/parameters/limitParam'
responses:
'200':
description: OK
How would I declare Swagger Annotations to produce this output, especially if the parameters are primitive type?
I tried
@Schema(type = "int")
@OpenAPIDefinition(info = @Info(description = "descr"))
public class OffsetParam {
public static final String DESCRIPTION =
"The number of items to skip before starting to collect the result set.";
@Parameter(description = "desc1")
public static OffsetParam valueOf(String value) {
return null;
}
}
but I only got
"components" : {
"schemas" : {
"OffsetParam" : {
"type" : "object"
},...
Do you have any idea which v3 annotations to add to a JAX-RS 2.1 resource? My goal is to define those common parameters once and refer to them in all resources across my application.