Skip to content

Instantly share code, notes, and snippets.

@tchafack
Last active August 28, 2022 14:29
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 tchafack/21e297d31466c1f80a5c24046073cbc4 to your computer and use it in GitHub Desktop.
Save tchafack/21e297d31466c1f80a5c24046073cbc4 to your computer and use it in GitHub Desktop.
Annotation Open API & Symfony : multipart/form-data requestBody
/**
* ...
*
* @OA\Schema(
* schema="CategoryPost",
* type="object",
* ...
*
* @OA\Property(
* type="object",
* property="parent",
* required={"id"},
* @OA\Property(type="integer", property="id", example=12),
* ),
* )
*
*...
*/
class Category
{
...
}
class MyController extends AbstractController
{
/**
* ...
*
* @OA\Post(
* tags={"Categories"},
* path="/api/categories",
* description="Create a category for company",
* security={
* {"Bearer": {}}
* },
* @OA\RequestBody(
* required=true,
* @OA\MediaType(
* mediaType="multipart/form-data",
* @OA\Schema(ref="#/components/schemas/CategoryPost"),
* ),
* ),
*
* ...
* )
*
*/
public function __invoke()
{
...
}
}
@tchafack
Copy link
Author

You'll have this :

Postman

Screenshot from 2022-08-28 16-26-53

Swagger
Screenshot from 2022-08-28 16-27-18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment