Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OpenApi/Factory/OpenApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection
$operationInputSchemas = [];
foreach ($requestMimeTypes as $operationFormat) {
$operationInputSchema = null;
if (str_starts_with($operationFormat, 'json')) {
if (str_starts_with($operationFormat, 'json') || 'multipart' === $operationFormat) {
$operationInputSchema = $this->jsonSchemaFactory->buildSchema($resourceClass, $operationFormat, Schema::TYPE_INPUT, $operation, $schema, null, $forceSchemaCollection);
$this->appendSchemaDefinitions($schemas, $operationInputSchema->getDefinitions());
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Fixtures/TestBundle/Entity/Issue7436/Issue7436.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7436;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Post;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;

#[ApiResource(
operations: [
new Post(
inputFormats: ['multipart' => ['multipart/form-data']],
),
]
)]
#[ORM\Entity]
class Issue7436
{
#[ORM\Column(type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
public ?UploadedFile $file = null;

public function getId()
{
return $this->id;
}
}
25 changes: 25 additions & 0 deletions tests/Functional/OpenApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyFriend;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritance;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyTableInheritanceChild;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Issue7436\Issue7436;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\JsonSchemaResource;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\JsonSchemaResourceRelated;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\NoCollectionDummy;
Expand Down Expand Up @@ -100,6 +101,7 @@ public static function getResources(): array
JsonSchemaResource::class,
JsonSchemaResourceRelated::class,
WrappedResponseEntity::class,
Issue7436::class,
];
}

Expand Down Expand Up @@ -610,4 +612,27 @@ public function testRetrieveTheEntrypointWithUrlFormat(): void
$this->assertResponseHeaderSame('content-type', 'application/vnd.openapi+json; charset=utf-8');
$this->assertJson($response->getContent());
}

public function testMultipartOperationHasCorrectOpenApiSchema(): void
{
$response = self::createClient()->request('GET', '/docs', [
'headers' => ['Accept' => 'application/vnd.openapi+json'],
]);
$this->assertResponseIsSuccessful();
$json = $response->toArray();

$this->assertSame(
[
'type' => ['string', 'null'],
'format' => 'binary',
],
$json['components']['schemas']['Issue7436']['properties']['file']
);
$this->assertSame(
[
'multipart/form-data' => ['schema' => ['$ref' => '#/components/schemas/Issue7436']],
],
$json['paths']['/issue7436s']['post']['requestBody']['content']
);
}
}
Loading