Search code examples
jsonswaggerswagger-uiswagger-2.0

Swagger UI - Multiple parameters in body overrides last variable value


I have the following documentation for my authentication route:

enter image description here

That is currently being generated through this 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"
                }
            }
        ],

The problem is, when I try to use the Try it out! feature and fills the email and password fields with the correct values and execute the requests, my browser is sending this request:

enter image description here

As you can see, it is just sending the password when, actually, should send: {"email": "gustavo-olegario@hotmail.com", "password": "12345678"}. Why this is happening? Is it a miss configuration on the JSON file?


Solution

  • I'm not sure to understand your question...

    If you are trying to define more than one body parameter for one operation, you can't. As explained in swagger specification:

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

    If you are trying to send a body with multiple parameters, add an object model in the definitions section and refer it in your body parameter.

    For more details: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object