@@ -670,7 +670,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string
670670 && ($ className = $ collectionValueType ->getClassName ())
671671 && $ this ->resourceClassResolver ->isResourceClass ($ className )
672672 ) {
673- $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className ), $ attribute , $ format );
673+ $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className, $ propertyMetadata ), $ attribute , $ format );
674674
675675 // @see ApiPlatform\Hal\Serializer\ItemNormalizer:getComponents logic for intentional duplicate content
676676 // @see ApiPlatform\JsonApi\Serializer\ItemNormalizer:getComponents logic for intentional duplicate content
@@ -707,7 +707,7 @@ protected function getAttributeValue(object $object, string $attribute, ?string
707707 ($ className = $ type ->getClassName ())
708708 && $ this ->resourceClassResolver ->isResourceClass ($ className )
709709 ) {
710- $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className ), $ attribute , $ format );
710+ $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className, $ propertyMetadata ), $ attribute , $ format );
711711 unset($ childContext ['iri ' ], $ childContext ['uri_variables ' ], $ childContext ['item_uri_template ' ]);
712712 if ('jsonld ' === $ format && $ uriTemplate = $ propertyMetadata ->getUriTemplate ()) {
713713 $ operation = $ this ->resourceMetadataCollectionFactory ->create ($ className )->getOperation (
@@ -749,22 +749,18 @@ protected function getAttributeValue(object $object, string $attribute, ?string
749749
750750 // Anonymous resources
751751 if ($ className ) {
752- $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className ), $ attribute , $ format );
753- $ childContext ['output ' ]['gen_id ' ] = $ propertyMetadata ->getGenId () ?? true ;
754-
752+ $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ className , $ propertyMetadata ), $ attribute , $ format );
755753 $ attributeValue = $ this ->propertyAccessor ->getValue ($ object , $ attribute );
756754
757755 return $ this ->serializer ->normalize ($ attributeValue , $ format , $ childContext );
758756 }
759757
760758 if ('array ' === $ type ->getBuiltinType ()) {
761759 if ($ className = ($ type ->getCollectionValueTypes ()[0 ] ?? null )?->getClassName()) {
762- $ context = $ this ->createOperationContext ($ context , $ className );
760+ $ context = $ this ->createOperationContext ($ context , $ className, $ propertyMetadata );
763761 }
764762
765763 $ childContext = $ this ->createChildContext ($ context , $ attribute , $ format );
766- $ childContext ['output ' ]['gen_id ' ] = $ propertyMetadata ->getGenId () ?? true ;
767-
768764 $ attributeValue = $ this ->propertyAccessor ->getValue ($ object , $ attribute );
769765
770766 return $ this ->serializer ->normalize ($ attributeValue , $ format , $ childContext );
@@ -820,12 +816,12 @@ protected function normalizeCollectionOfRelations(ApiProperty $propertyMetadata,
820816 */
821817 protected function normalizeRelation (ApiProperty $ propertyMetadata , ?object $ relatedObject , string $ resourceClass , ?string $ format , array $ context ): \ArrayObject |array |string |null
822818 {
823- if (null === $ relatedObject || !empty ($ context ['attributes ' ]) || $ propertyMetadata ->isReadableLink ()) {
819+ if (null === $ relatedObject || !empty ($ context ['attributes ' ]) || $ propertyMetadata ->isReadableLink () || false === ( $ context [ ' output ' ][ ' gen_id ' ] ?? true ) ) {
824820 if (!$ this ->serializer instanceof NormalizerInterface) {
825821 throw new LogicException (\sprintf ('The injected serializer must be an instance of "%s". ' , NormalizerInterface::class));
826822 }
827823
828- $ relatedContext = $ this ->createOperationContext ($ context , $ resourceClass );
824+ $ relatedContext = $ this ->createOperationContext ($ context , $ resourceClass, $ propertyMetadata );
829825 $ normalizedRelatedObject = $ this ->serializer ->normalize ($ relatedObject , $ format , $ relatedContext );
830826 if (!\is_string ($ normalizedRelatedObject ) && !\is_array ($ normalizedRelatedObject ) && !$ normalizedRelatedObject instanceof \ArrayObject && null !== $ normalizedRelatedObject ) {
831827 throw new UnexpectedValueException ('Expected normalized relation to be an IRI, array, \ArrayObject or null ' );
@@ -917,7 +913,7 @@ private function createAndValidateAttributeValue(string $attribute, mixed $value
917913 && $ this ->resourceClassResolver ->isResourceClass ($ className )
918914 ) {
919915 $ resourceClass = $ this ->resourceClassResolver ->getResourceClass (null , $ className );
920- $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ resourceClass ), $ attribute , $ format );
916+ $ childContext = $ this ->createChildContext ($ this ->createOperationContext ($ context , $ resourceClass, $ propertyMetadata ), $ attribute , $ format );
921917
922918 try {
923919 return $ this ->denormalizeRelation ($ attribute , $ propertyMetadata , $ resourceClass , $ value , $ format , $ childContext );
0 commit comments