Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Swagger UI Grouping Not Working with Symfony Serializer Groups #2414

Open
e-vural opened this issue Dec 30, 2024 · 0 comments
Open

[Bug]: Swagger UI Grouping Not Working with Symfony Serializer Groups #2414

e-vural opened this issue Dec 30, 2024 · 0 comments
Labels

Comments

@e-vural
Copy link

e-vural commented Dec 30, 2024

Version

4.33

Description

I encountered an issue when using the Groups attribute from Symfony's built-in serializer (Symfony\Component\Serializer\Attribute\Groups) in my Symfony 7 project. The grouping seems to work correctly within Symfony's serialization process, but it doesn't reflect properly in the Swagger UI (using NelmioApiDocBundle).

Here is an example of the entity property where the problem occurs:

  use Symfony\Component\Serializer\Attribute\Groups;  
  use Doctrine\ORM\Mapping as ORM;  
  use App\SerializerGroups;  
  
  #[ORM\Column(nullable: true)]  
  #[Groups([SerializerGroups::PUBLIC])]  
  private ?int $number = null;  

When I switch to using JMS\Serializer\Annotation\Groups, everything works fine in the Swagger UI:

  use JMS\Serializer\Annotation\Groups;  
  use Doctrine\ORM\Mapping as ORM;  

  #[ORM\Column(nullable: true)]  
  #[Groups([SerializerGroups::PUBLIC])]  
  private ?int $number = null;

It appears there is a lack of full integration between Symfony's serializer and the Swagger documentation generator.

Usage:

    #[OA\Response(
        response: 200,
        description: 'Successful response',
        content: new Model(type: CurrencyEntity::class, groups: [SerializerGroups::PUBLIC])
    )]

Steps to Reproduce:

Create an entity and use Symfony's Groups attribute (Symfony\Component\Serializer\Attribute\Groups).
Define the serialization groups for an API endpoint in the controller.
Check the Swagger UI documentation generated by NelmioApiDocBundle.
Expected Behavior:
The Groups attribute from Symfony's built-in serializer should work seamlessly with Swagger UI to group properties correctly in the API documentation.

Actual Behavior:
The properties annotated with Symfony's Groups attribute do not appear correctly grouped in Swagger UI.

Additional Context:

Symfony version: 7.2
NelmioApiDocBundle version: [4.33]
PHP version: [8.3]
Any relevant configuration or setup details
I would appreciate any guidance on whether this is a known issue, a configuration problem, or if there are plans to enhance the integration.

JSON OpenApi

JSON OpenApi
Replace this text with your JSON (`bin/console nelmio:apidoc:dump`)

Additional context

No response

@e-vural e-vural added the bug label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant