api-platform icon indicating copy to clipboard operation
api-platform copied to clipboard

Generated Open-API documentation doesn't work with multipart and arrays

Open NotionCommotion opened this issue 4 years ago • 1 comments

API Platform version(s) affected: 2..6.4

Description

The autogenerated Open-API documentation for multipart prompts the user to enter a list of strings which presumably should be sent as an array like string, but sends it as a comma delineated list.

How to reproduce

When making a multipart request, the open-api documentation shows as:

image

and the request looks like:

curl -X 'POST' \
  'https://example.com/media' \
  -H 'accept: application/ld+json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'documents=documents/1,documents/2' \
  -F 'file=@nature-gabc8f8c92_1920.jpe;type=image/jpeg'

and the decoder doesn't convert it to an array,

Possible Solution

Change the request from:

curl -X 'POST' \
   ..
  -F 'documents=documents/1,documents/2' \
   ..

to

curl -X 'POST' \
   ..
  -F 'documents=["documents/1", "documents/2]"' \
   ..

A workaround is to include an array like string in a single list item, but I don't think doing so is the intent. image

Additional Context

My entity looks like:

#[ORM\Entity]
#[ApiResource(
    collectionOperations: [
        'post' => [
            'input_formats' => [
                'multipart' => ['multipart/form-data'],
            ],
        ],
        'get',
    ]
)]
class Media extends AbstractPublicIdTenantEntity implements HasPhysicalMediaInterface
{

    #[ORM\ManyToMany(targetEntity: Document::class, mappedBy: 'medias')]
    private Collection $documents;
	// ...
}

NotionCommotion avatar Jan 18 '22 17:01 NotionCommotion

Same here. Is there any possible fix?

riskersen avatar Apr 20 '22 08:04 riskersen