Last active
January 9, 2022 15:16
-
-
Save pavel-vasiluk/45602deb0959ae79195424791e789136 to your computer and use it in GitHub Desktop.
NelmioApiDocBundle - multipart/form-data request with file and POST parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Post request OpenAPI definition in controller | |
use Nelmio\ApiDocBundle\Annotation\Model; | |
use OpenApi\Annotations as OA; | |
use Symfony\Component\HttpFoundation\Response; | |
@OA\Post( | |
description="Submit verification document", | |
@OA\RequestBody( | |
@OA\MediaType( | |
mediaType="multipart/form-data", | |
schema=@OA\Schema(ref=@Model(type=VerificationRequestDTO::class, groups={"documentation"})) | |
) | |
), | |
@OA\Response( | |
response=Response::HTTP_NO_CONTENT, | |
description="Returns verification response" | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Request DTO has POST parameter (type) and uploaded file (file). Request Content-Type header is multipart/form-data | |
// Instead of request DTO it can be also Entity or any other model class you need | |
// Please note: file is documented as string property with binary format | |
class VerificationRequestDTO | |
{ | |
/** | |
* @OA\Property( | |
* property="type", | |
* type="string", | |
* description="Verification document type", | |
* example="passport" | |
* ) | |
* | |
* @Groups({"documentation"}) | |
*/ | |
protected $type; | |
/** | |
* @OA\Property( | |
* property="file", | |
* type="string", | |
* format="binary", | |
* description="Verification document file" | |
* ) | |
* | |
* @Groups({"documentation"}) | |
*/ | |
protected $file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment