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 ?
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 ?
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
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"; }
. –
Marmoset For swagger version 3, you can use the annotation @Parameter
import io.swagger.v3.oas.annotations.Parameter
https://docs.swagger.io/swagger-core/v2.0.0-RC3/apidocs/io/swagger/v3/oas/annotations/Parameter.html
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"
},
...
}
}
},
...
}
Building on @Ilya Y
's answer here's a snippet from a controller I had using io.swagger.v3.oas.annotations.Parameter;
@PostMapping("/report")
public FileItem generateReport(
@RequestParam String projectId,
@RequestParam @DateTimeFormat(iso = ISO.DATE) @Parameter(schema = @Schema(type = "string", description = "Date in ISO format (yyyy-MM-dd)")) LocalDate date,
@RequestParam(defaultValue = "UTC") String zoneId //
) {
...
}
© 2022 - 2024 — McMap. All rights reserved.