POST arrray with swagger UI

30 views
Skip to first unread message

Plamen Vasilev

unread,
May 22, 2015, 11:42:57 AM5/22/15
to swagger-sw...@googlegroups.com
Hi Swaggers,

I have the following issue.
I have build rest api to create invoices.
The invoice have array of items
the definition is:

'definitions' => array(
    'InvoiceItems' => array(
        'type' => 'object',
        'required' => array(
            'name',
            'quantity',
            'price',
        ),
        'properties'=> array(
            'name' => array(
                'type' => 'string',
                'required' => true,
            ),
            'quantity' => array(
                'type' => 'float',
            ),
            'price' => array(
                'type' => 'float',
            ),
        )
    )
)

and the parameter is

'parameters' => array(
    array(
        'required' => true,
        'name' => 'items',
        'in' => 'formData',
        'description' => 'desc ..',
        "schema" => array(
            '$ref' => "#/definitions/InvoiceItems",
        ),
        'type' => 'array',
        'collectionFormat' =>'multi',
    ),
)

Is it possible when I do POST this array of arrays ?

The swagger UI shows me only an input and the schema definition on the right, but I cannot fill any of the elements

Plamen Vasilev

unread,
May 22, 2015, 11:47:52 AM5/22/15
to swagger-sw...@googlegroups.com
If I write into the input this

[{"name":"bananas", "quantity":1, "price":1}]

on the server the POST data is as a string

array(1) {
  ["items"]=>
  string(45) "[{"name":"bananas", "quantity":1, "price":1}]"
}

can I post this as array ? not as a string?

Ron Ratovsky

unread,
May 23, 2015, 9:54:51 AM5/23/15
to swagger-sw...@googlegroups.com
In Swagger 2, you cannot use models as values for form parameters, directly or in an array.
If it's a single parameter, you should treat it as a body parameter with the appropriate mime type.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Plamen Vasilev

unread,
May 25, 2015, 6:00:33 AM5/25/15
to swagger-sw...@googlegroups.com
When I set the "in" to "body" i get a textare in which I can paste the code and select content type, but If I change the "in" to "formData" i get only input field with no content type select option.

Is this a bug ?


On Saturday, May 23, 2015 at 4:54:51 PM UTC+3, Ron wrote:
In Swagger 2, you cannot use models as values for form parameters, directly or in an array.
If it's a single parameter, you should treat it as a body parameter with the appropriate mime type.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Ron Ratovsky

unread,
May 26, 2015, 10:46:15 AM5/26/15
to swagger-sw...@googlegroups.com
You can't just change the "in" to "body" because the structure of "body" parameters is slightly different.
You need to move all the type definitions under the "schema" property. Take a look at our pet store for example.

http://petstore.swagger.io
http://petstore.swagger.io/v2/swagger.json

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages