My Annotations looks like this:
@OA\RequestBody(
* description="Mark notifications as read",
* required=true,
* @OA\MediaType(
* mediaType="application/x-www-form-urlencoded",
* @OA\Schema(
* type="object",
* @OA\Property(
* property="notifications",
* description="Array containing log ids",
* type="array",
* @OA\Items(
* @OA\Items(type="integer"),
* )
* ),
* ),
* ),
* )
I can fill an array in Swagger UI, but it returns a comma delimited list of id's.
There are several options available: https://swagger.io/docs/specification/serialization/
I can't get it to work, I see some examples in this repo but it's all using GET parameter. I cant find out how to use it in my current situation. Do you have a working example for me maybe?
Ah, I linked a related page, see the Form section in Describing Request Body
I don't have an example, nor do i know what you expected to happen.
I did see you have nested one @OA\Items() too many.
You might want to experiment with encoding, explode: true and changing the property name to "notifications[]"
I tried many different ways, just in the swagger UI code editor to see if I could get it work but still cant find out how to retrieve an array instead of a comma delimited list.
My current YML file looks like this:
requestBody:
description: 'Mark notifications as read'
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
notifications:
type: array
items:
type: string
What I want is to send an array. I can add multiple items to notifications in Swagger UI, so that is working nicely. The problem is how the data is being send out, because its sending data like a comma delimited list instead of an array.
So for example:
I add 3 id's in swagger UI (With adding items):
- 1
- 2
- 3
How I expect to receive the values (because I added type: array):
[notifications] => [1,2,3]
However, I receive the values like this:
[notifications] => '1,2,3'
I'm closing this issue, as it is not an issue in swagger-php.
swagger-php is only responsible for generating the yaml/json from annotations.
Ah, I linked a related page, see the Form section in Describing Request Body
I don't have an example, nor do i know what you expected to happen.
I did see you have nested one@OA\Items()too many.You might want to experiment with
encoding,explode: trueand changing the property name to "notifications[]"
How do you use encoding & explode with annotations ?
how do you resolve that problem ? @sdrenth
@sdrenth @svilborg @kiramishima I know my answer is a bit too late but I hope my code helpful to you guys in future development.
* @OA\RequestBody(
* description="Input data formats",
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* encoding={
* "pledges[]": {
* "explode": true,
* },
* },
* @OA\Schema(
* type="object",
* required={
* "pledges"
* },
* @OA\Property(
* property="pledges[]",
* type="array",
* description="Pledge id from pledge list api",
* @OA\Items(
* @OA\Items(type="integer"),
* ),
* ),
* ),
* ),
* ),
Most helpful comment
@sdrenth @svilborg @kiramishima I know my answer is a bit too late but I hope my code helpful to you guys in future development.