I’m having trouble configuring the generation of API documentation using NelmioApiDocBundle with Symfony. I’m trying to add annotations to describe my routes, but it doesn’t seem to be working as expected.
I am required to use the #[...]
format for annotations due to the version of Symfony I’m using, rather than the traditional /** ... */
format.
Here’s the code for my controller:
#[Route('/badges', name: 'api_list_badges', methods: ['GET'])]
#[
OAGet(
description: 'Lists all badges',
summary: 'Lists all badges of all users',
responses: [
new OAResponse(
response: 200,
description: 'Success',
content: new OAJsonContent(ref: new Model(type: Badge::class), type: 'object')
),
new OAResponse(response: 500, description: 'Internal Server Error'),
]
)
]
public function getAll(){
$badges = $this->badgeRepository->findAll();
$data = $this->serializer->serialize($badges, 'json', ['groups' => 'list_badge']);
return new JsonResponse($data, 200, [], true);
}
And here’s my YAML configuration for NelmioApiDocBundle:
nelmio_api_doc:
documentation:
info:
title: 'TEST'
description: 'This is the API documentation.'
version: '1.0.0'
areas:
default:
path_patterns: ['^/api(?!/doc$)']
models:
use_jms: false
use_validation_groups: true
I’m particularly confused about the following points:
-
Are the annotations in my code correctly formatted to be recognized by NelmioApiDocBundle?
-
Is there any additional configuration required to ensure the annotations are properly processed and included in the generated documentation?
-
Are there any specific options in my YAML configuration that I need to check to make sure the annotations are properly considered?
Thank you in advance for your help! Any suggestions or solutions would be greatly appreciated.