Swagger UI-主体中的多个参数会覆盖最后一个变量值

时间:2019-07-30 19:00:23

标签: json swagger swagger-ui swagger-2.0

我具有以下有关身份验证路由的文档:

enter image description here

当前正在通过此JSON生成:

"post": {
        "description": "Authenticate an user",
        "tags": [
            "session"
        ],
        "consumes": "application/json",
        "parameters": [
            {
                "name": "email",
                "in": "body",
                "description": "user email",
                "required": true,
                "schema": {
                    "type": "string"
                }
            },
            {
                "name": "password",
                "in": "body",
                "description": "user password",
                "required": true,
                "schema": {
                    "type": "string"
                }
            }
        ],

问题是,当我尝试使用Try it out!功能并用正确的值填充电子邮件和密码字段并执行请求时,我的浏览器正在发送此请求:

enter image description here

如您所见,实际上只是在发送密码时发送{"email": "gustavo-olegario@hotmail.com", "password": "12345678"}。 为什么会这样呢? JSON文件上是否缺少配置?

1 个答案:

答案 0 :(得分:2)

我不确定您的问题...

如果您要为一项操作定义多个body参数,则不能。如大摇大摆的规范所述:

Body [...] there can only be one body parameter

如果您要发送带有多个参数的主体,请在“定义”部分添加一个对象模型,然后在您的主体参数中引用它。

有关更多详细信息: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object

编辑:

为了提高安全性,请在header属性中发送密码。