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

feat(serializer): check in child classes attribute's groups for serialization #6382

Open
wants to merge 1 commit into
base: 3.3
Choose a base branch
from

Conversation

antoine-nedelec
Copy link

@antoine-nedelec antoine-nedelec commented May 21, 2024

Q A
Branch? 3.3
Tickets N/A
License MIT
Doc PR N/A

Original issue created:

Self contained repository for reproduction:

Overall logic:

  • When fetching the groups for a serialization, there might be a group filled only for one child class. and not available in any parent attributes. The entity is then serialized as an IRI, but there could have been specific attributes to be serialized.

Remarks:

  • Not sure if this behavior should be limited with a configuration as I did ?
  • Name of the attribute to be defined ?

@antoine-nedelec antoine-nedelec changed the base branch from main to 3.3 May 21, 2024 22:07
@antoine-nedelec antoine-nedelec force-pushed the feat/normalize-child-class-attribute-groups branch 3 times, most recently from 723f297 to ead9c6c Compare May 21, 2024 22:42
@antoine-nedelec antoine-nedelec changed the title feat(Serializer) Check in child classes attribute's groups for serialization feat(Serializer): Check in child classes attribute's groups for serialization May 21, 2024
@antoine-nedelec antoine-nedelec force-pushed the feat/normalize-child-class-attribute-groups branch 4 times, most recently from c5572f7 to c7c625f Compare May 23, 2024 09:11
@antoine-nedelec antoine-nedelec changed the title feat(Serializer): Check in child classes attribute's groups for serialization feat(serializer): sheck in child classes attribute's groups for serialization May 23, 2024
@antoine-nedelec antoine-nedelec force-pushed the feat/normalize-child-class-attribute-groups branch from c7c625f to 01d4c0f Compare May 23, 2024 09:35
@antoine-nedelec antoine-nedelec changed the title feat(serializer): sheck in child classes attribute's groups for serialization feat(serializer): check in child classes attribute's groups for serialization May 23, 2024
@@ -203,6 +204,18 @@ private function getClassSerializerGroups(string $class): array
$groups[] = $serializerAttributeMetadata->getGroups();
}

if (true === $this->normalizeChildClassAttributeGroups) {
foreach ($serializerClassMetadata->getReflectionClass()->getAttributes() as $reflectionAttribute) {
if (DiscriminatorMap::class !== $reflectionAttribute->getName()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is discriminatorMap an attribute of the serializer? not sure I understand how this works.

@@ -17,6 +17,7 @@
use ApiPlatform\Metadata\Exception\ResourceClassNotFoundException;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use ApiPlatform\Metadata\Util\ResourceClassInfoTrait;
use Doctrine\ORM\Mapping\DiscriminatorMap;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a huge fan of using doctrine in this file, it'd be best inside DoctrineOrmPropertyMetadataFactory?

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

Successfully merging this pull request may close these issues.

2 participants