如何在Swagger(OpenAPI)中定义互斥查询参数? [英] How to define mutually exclusive query parameters in Swagger (OpenAPI)?

查看:109
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆