-
-
Notifications
You must be signed in to change notification settings - Fork 921
fix #1980 user defined property metadata takes precedence #1997
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,9 +93,6 @@ private function transformReadWrite(PropertyMetadata $propertyMetadata, string $ | |
*/ | ||
private function transformLinkStatus(PropertyMetadata $propertyMetadata, array $normalizationGroups = null, array $denormalizationGroups = null): PropertyMetadata | ||
{ | ||
$propertyMetadata = $propertyMetadata->withReadableLink(true); | ||
$propertyMetadata = $propertyMetadata->withWritableLink(true); | ||
|
||
// No need to check link status if property is not readable and not writable | ||
if (false === $propertyMetadata->isReadable() && false === $propertyMetadata->isWritable()) { | ||
return $propertyMetadata; | ||
|
@@ -109,7 +106,7 @@ private function transformLinkStatus(PropertyMetadata $propertyMetadata, array $ | |
$relatedClass = $type->isCollection() && ($collectionValueType = $type->getCollectionValueType()) ? $collectionValueType->getClassName() : $type->getClassName(); | ||
|
||
if (null === $relatedClass) { | ||
return $propertyMetadata; | ||
return $propertyMetadata->withReadableLink(true)->withWritableLink(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kinda prevents the break, to me these should stay There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I don't think this is correct, as this class is only supposed to fill in the metadata based on the Symfony Serializer mapping. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm totally 👍 to remove this but this has some impacts down the road. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... Now I see we were already doing this from before. 😱 I guess let's keep it then. Haha... |
||
} | ||
|
||
// No need to check link status if related class is not a resource | ||
|
@@ -121,8 +118,13 @@ private function transformLinkStatus(PropertyMetadata $propertyMetadata, array $ | |
|
||
$relatedGroups = $this->getResourceSerializerGroups($relatedClass); | ||
|
||
$propertyMetadata = $propertyMetadata->withReadableLink(null !== $normalizationGroups && !empty(array_intersect($normalizationGroups, $relatedGroups))); | ||
$propertyMetadata = $propertyMetadata->withWritableLink(null !== $denormalizationGroups && !empty(array_intersect($denormalizationGroups, $relatedGroups))); | ||
if (null === $propertyMetadata->isReadableLink()) { | ||
$propertyMetadata = $propertyMetadata->withReadableLink(null !== $normalizationGroups && !empty(array_intersect($normalizationGroups, $relatedGroups))); | ||
} | ||
|
||
if (null === $propertyMetadata->isWritableLink()) { | ||
$propertyMetadata = $propertyMetadata->withWritableLink(null !== $denormalizationGroups && !empty(array_intersect($denormalizationGroups, $relatedGroups))); | ||
} | ||
|
||
return $propertyMetadata; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity; | ||
|
||
use ApiPlatform\Core\Annotation\ApiProperty; | ||
use ApiPlatform\Core\Annotation\ApiResource; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
/** | ||
* @ApiResource | ||
* @ORM\Entity | ||
*/ | ||
class ReadableOnlyProperty | ||
{ | ||
/** | ||
* @var int The id | ||
* | ||
* @ORM\Column(type="integer") | ||
* @ORM\Id | ||
* @ORM\GeneratedValue(strategy="AUTO") | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string The foo name | ||
* | ||
* @ORM\Column | ||
* @ApiProperty(writable=false) | ||
*/ | ||
private $name; | ||
|
||
public function __construct() | ||
{ | ||
$this->name = 'Read only'; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function setName($name) | ||
{ | ||
throw new \Exception('Can not write name.'); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.