java Swagger ui - 查询参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31169622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Swagger ui - Query param
提问by Jacaro
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...
我正在将 Swagger ui 和 Swagger 核心 (1.3) 用于球衣应用程序。我有某些查询参数,我必须随每个请求发送这些参数,例如 post、get、delete...
How can I default this ?
我怎么能默认这个?
回答by ipeluffo
You can use the annotation @ApiParam
from the Swagger annotations in order to configure the Query param to be used from the Swagger-UI.
您可以使用@ApiParam
Swagger 注释中的注释来配置要从 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
请在以下官方文档中阅读有关此注释的更多信息:https: //github.com/swagger-api/swagger-core/wiki/Annotations#apiparam
回答by Nelson G.
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.
你不能,但是因为 swagger 2.0(我不知道这是否被 swagger-code/swagger-ui 支持),你可以定义参数以在操作中重用。
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"
},
...
}
}
},
...
}