Swagger-php: Unable to send POST body with consumes x-www-form-urlencoded

Created on 4 Jan 2016  路  4Comments  路  Source: zircote/swagger-php

I'm trying to test my API using Swagger UI, but it is not sending the body of my request.
This is how the comments are formatted:

/**
 * @SWG\Post(
 *     path="/users",
 *     summary="Create user",
 *     tags={"users"},
 *     description="Add new user to Fantatletica table",
 *     operationId="postUser",
 *     consumes={"application/x-www-form-urlencoded"},
 *     produces={"application/json"},
 *     @SWG\Parameter(
 *         name="body",
 *         in="body",
 *         description="User object that needs to be added to the local table",
 *         required=true,
 *         @SWG\Schema(ref="#/definitions/User"),
 *     ),
     *     @SWG\Parameter(
 *         name="token",
 *         in="query",
 *         description="Token",
 *         required=true,
 *         type="string"
 *     ),
 *     security={
 *         {"api_key": {} }
 *     },
 *     @SWG\Response(
 *         response=200,
 *         description="Success",
 *         @SWG\Schema(
 *             type="object",
 *             @SWG\Property(property="error",type="boolean"),
 *             @SWG\Property(
 *                 property="data",
 *                 type="array",
 *                 @SWG\Items(ref="#/definitions/User")
 *             ),
 *         @SWG\Property(property="message",type="string"),
 *             @SWG\Property(property="response_code",type="string")
 *         ),
 *     )
 * )
 */

And this is the resulting JSON

       "post": {
            "tags": [
                "users"
            ],
            "summary": "Create user",
            "description": "Add new user to Fantatletica table",
            "operationId": "postUser",
            "consumes": [
                "application/x-www-form-urlencoded"
            ],
            "produces": [
                "application/json"
            ],
            "parameters": [
                {
                    "name": "body",
                    "in": "body",
                    "description": "User object that needs to be added to the local table",
                    "required": true,
                    "schema": {
                        "$ref": "#/definitions/User"
                    }
                },
                {
                    "name": "token",
                    "in": "query",
                    "description": "Token",
                    "required": true,
                    "type": "string"
                }
            ],
            "responses": {
                "200": {
                    "description": "Success",
                    "schema": {
                        "properties": {
                            "error": {
                                "type": "boolean"
                            },
                            "data": {
                                "type": "array",
                                "items": {
                                    "$ref": "#/definitions/User"
                                }
                            },
                            "message": {
                                "type": "string"
                            },
                            "response_code": {
                                "type": "string"
                            }
                        },
                        "type": "object"
                    }
                }
            },
            "security": [
                {
                    "api_key": []
                }
            ]
        }

In the resulting curl does not appear any -d string

Most helpful comment

how to solve this issue in swagger 3.0 ?

All 4 comments

Instead of using 1 parameter with in="body" use multiple parameters with in="formData"

Is working, thanks!

can anyone make an example in detail for me @mikylucky @bfanger ,thanks

how to solve this issue in swagger 3.0 ?

Was this page helpful?
0 / 5 - 0 ratings