Skip to content

Instantly share code, notes, and snippets.

@pavel-vasiluk
Last active January 9, 2022 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pavel-vasiluk/45602deb0959ae79195424791e789136 to your computer and use it in GitHub Desktop.
Save pavel-vasiluk/45602deb0959ae79195424791e789136 to your computer and use it in GitHub Desktop.
NelmioApiDocBundle - multipart/form-data request with file and POST parameters
// 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"
)
)
// 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