如何在Swagger(OpenAPI)中定义互斥查询参数? [英] How to define mutually exclusive query parameters in Swagger (OpenAPI)?
问题描述
我在Swagger中有一系列这样的参数
I have a series of parameters in Swagger like this
"parameters": [
{
"name": "username",
"description": "Fetch username by username/email",
"required": false,
"type": "string",
"paramType": "query"
},
{
"name": "site",
"description": "Fetch username by site",
"required": false,
"type": "string",
"paramType": "query"
},
{
"name": "survey",
"description": "Fetch username by survey",
"required": false,
"type": "string",
"paramType": "query"
}
],
必须填写一个参数,但是哪个参数无关紧要,其他参数可以留空.有没有一种方法可以在Swagger中表示出来?
One parameter MUST be filled out but it doesn't matter which one, the others can be left blank. Is there a way to represent this in Swagger?
推荐答案
不幸的是,这目前在Swagger中是不可能的. "required"只是一个布尔值,无法表示参数之间的相互依赖性.
Unfortunately this isn't possible in Swagger currently. "required" is just a boolean and there's no way to represent interdependencies between parameters.
最好的办法是在参数描述中明确要求,并在同一行中放入自定义的400 Bad Request描述.
Best you can do is make clear the requirements in the parameter descriptions and also put in a custom 400 Bad Request description along the same lines.
(在 https://github.com/swagger中进行了一些讨论-api/swagger-spec/issues/256 关于在下一版Swagger中实现此方法的可能方式)
(There's a bit of discussion at https://github.com/swagger-api/swagger-spec/issues/256 about possible ways of implementing this in the next version of Swagger)
这篇关于如何在Swagger(OpenAPI)中定义互斥查询参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!