Last active
February 19, 2024 13:43
-
-
Save atlance/7b03a1cb117de10c7fd2cf829e9cce89 to your computer and use it in GitHub Desktop.
attributes for nelmio api doc
This file contains hidden or 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
| <?php | |
| declare(strict_types=1); | |
| // ... | |
| use OpenApi\Attributes as OA; | |
| use Symfony\Component\HttpFoundation\Response; | |
| use Symfony\Component\Routing\Annotation\Route; | |
| #[OA\Get( | |
| tags: ['foo-bar'], | |
| description: 'Oh Yeah!!!', | |
| parameters: [ | |
| new OA\Parameter(ref: '#/components/parameters/version'), | |
| ], | |
| responses: [ | |
| new OA\Response( | |
| response: Response::HTTP_OK, | |
| description: 'code 200, example array of objects.', | |
| content: new OA\JsonContent( | |
| type: 'array', | |
| items: new OA\Items(ref: new Model(type: UserIdentity::class, groups: ['full'])) | |
| ) | |
| ), | |
| new OA\Response( | |
| response: Response::HTTP_CREATED, | |
| description: 'code 201, example single object.', | |
| content: new OA\JsonContent(ref: new Model(type: UserIdentity::class, groups: ['full'])) | |
| ), | |
| new OA\Response( | |
| response: Response::HTTP_ACCEPTED, | |
| description: 'code 202, example custom object without model.', | |
| content: new OA\JsonContent( | |
| type: 'object', | |
| properties: [ | |
| new OA\Property(property: 'foo', type: 'string'), | |
| new OA\Property(property: 'bar', type: 'integer'), | |
| new OA\Property( | |
| property: 'baz', | |
| type: 'array', | |
| items: new OA\Items(ref: new Model(type: UserIdentity::class, groups: ['full'])) | |
| ), | |
| ] | |
| ) | |
| ), | |
| new OA\Response(response: Response::HTTP_BAD_REQUEST, description: 'code 400, sorry =('), | |
| new OA\Response(response: Response::HTTP_INTERNAL_SERVER_ERROR, description: 'code 500, ooops!'), | |
| ] | |
| )] | |
| #[Route(path: '/get/endpoint', name: 'get_endpoint', methods: ['GET'])] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment