Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions phpunit.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,19 @@
<issue><![CDATA[Since symfony/validator 7.1: Not passing a value for the "requireTld" option to the Url constraint is deprecated. Its default value will change to "true".]]></issue>
</line>
</file>
<file path="src/Metadata/Resource/Factory/MetadataCollectionFactoryTrait.php">
<line number="222" hash="29843c95ea9de65e8e7867216969c55e2c33d9e2">
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "SecuredDummy" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\SecuredDummy" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "RelatedDummy" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "Question" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\Question" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "Answer" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\Answer" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "ThirdLevel" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\ThirdLevel" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "RelatedToDummyFriend" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedToDummyFriend" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "Dummy" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "FourthLevel" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\FourthLevel" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "Employee" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\Employee" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "Company" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\Company" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
<issue><![CDATA[Since api-platform/core 4.2: Having multiple "#[ApiResource]" attributes with the same "shortName" "AttributeResource" on class "ApiPlatform\Tests\Fixtures\TestBundle\Entity\AttributeResource" is deprecated and will result in automatic short name deduplication in API Platform 5.x. Set "defaults.extra_properties.deduplicate_resource_short_names" to "true" in the API Platform configuration to enable it now.]]></issue>
</line>
</file>
</files>
46 changes: 22 additions & 24 deletions src/Hydra/Serializer/DocumentationNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
use ApiPlatform\Metadata\ResourceClassResolverInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use ApiPlatform\Metadata\Util\TypeHelper;
Expand Down Expand Up @@ -76,16 +75,17 @@ public function normalize(mixed $data, ?string $format = null, array $context =
foreach ($data->getResourceNameCollection() as $resourceClass) {
$resourceMetadataCollection = $this->resourceMetadataFactory->create($resourceClass);

$resourceMetadata = $resourceMetadataCollection[0];
if (true === $resourceMetadata->getHideHydraOperation()) {
continue;
}
foreach ($resourceMetadataCollection as $resourceMetadata) {
if (true === $resourceMetadata->getHideHydraOperation()) {
continue;
}

$shortName = $resourceMetadata->getShortName();
$prefixedShortName = $resourceMetadata->getTypes()[0] ?? "#$shortName";
$shortName = $resourceMetadata->getShortName();
$prefixedShortName = $resourceMetadata->getTypes()[0] ?? "#$shortName";

$this->populateEntrypointProperties($resourceMetadata, $shortName, $prefixedShortName, $entrypointProperties, $hydraPrefix, $resourceMetadataCollection);
$classes[] = $this->getClass($resourceClass, $resourceMetadata, $shortName, $prefixedShortName, $context, $hydraPrefix, $resourceMetadataCollection);
$this->populateEntrypointProperties($resourceMetadata, $shortName, $prefixedShortName, $entrypointProperties, $hydraPrefix);
$classes[] = $this->getClass($resourceClass, $resourceMetadata, $shortName, $prefixedShortName, $context, $hydraPrefix);
}
}

return $this->computeDoc($data, $this->getClasses($entrypointProperties, $classes, $hydraPrefix), $hydraPrefix);
Expand All @@ -94,9 +94,9 @@ public function normalize(mixed $data, ?string $format = null, array $context =
/**
* Populates entrypoint properties.
*/
private function populateEntrypointProperties(ApiResource $resourceMetadata, string $shortName, string $prefixedShortName, array &$entrypointProperties, string $hydraPrefix, ?ResourceMetadataCollection $resourceMetadataCollection = null): void
private function populateEntrypointProperties(ApiResource $resourceMetadata, string $shortName, string $prefixedShortName, array &$entrypointProperties, string $hydraPrefix): void
{
$hydraCollectionOperations = $this->getHydraOperations(true, $resourceMetadataCollection, $hydraPrefix);
$hydraCollectionOperations = $this->getHydraOperations(true, $resourceMetadata, $hydraPrefix);
if (empty($hydraCollectionOperations)) {
return;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ private function populateEntrypointProperties(ApiResource $resourceMetadata, str
/**
* Gets a Hydra class.
*/
private function getClass(string $resourceClass, ApiResource $resourceMetadata, string $shortName, string $prefixedShortName, array $context, string $hydraPrefix, ?ResourceMetadataCollection $resourceMetadataCollection = null): array
private function getClass(string $resourceClass, ApiResource $resourceMetadata, string $shortName, string $prefixedShortName, array $context, string $hydraPrefix): array
{
$description = $resourceMetadata->getDescription();
$isDeprecated = $resourceMetadata->getDeprecationReason();
Expand All @@ -145,7 +145,7 @@ private function getClass(string $resourceClass, ApiResource $resourceMetadata,
'@type' => $hydraPrefix.'Class',
$hydraPrefix.'title' => $shortName,
$hydraPrefix.'supportedProperty' => $this->getHydraProperties($resourceClass, $resourceMetadata, $shortName, $prefixedShortName, $context, $hydraPrefix),
$hydraPrefix.'supportedOperation' => $this->getHydraOperations(false, $resourceMetadataCollection, $hydraPrefix),
$hydraPrefix.'supportedOperation' => $this->getHydraOperations(false, $resourceMetadata, $hydraPrefix),
];

if (null !== $description) {
Expand Down Expand Up @@ -252,21 +252,19 @@ private function getHydraProperties(string $resourceClass, ApiResource $resource
/**
* Gets Hydra operations.
*/
private function getHydraOperations(bool $collection, ?ResourceMetadataCollection $resourceMetadataCollection = null, string $hydraPrefix = ContextBuilder::HYDRA_PREFIX): array
private function getHydraOperations(bool $collection, ApiResource $resourceMetadata, string $hydraPrefix = ContextBuilder::HYDRA_PREFIX): array
{
$hydraOperations = [];
foreach ($resourceMetadataCollection as $resourceMetadata) {
foreach ($resourceMetadata->getOperations() as $operation) {
if (true === $operation->getHideHydraOperation()) {
continue;
}

if (('POST' === $operation->getMethod() || $operation instanceof CollectionOperationInterface) !== $collection) {
continue;
}
foreach ($resourceMetadata->getOperations() as $operation) {
if (true === $operation->getHideHydraOperation()) {
continue;
}

$hydraOperations[] = $this->getHydraOperation($operation, $operation->getShortName(), $hydraPrefix);
if (('POST' === $operation->getMethod() || $operation instanceof CollectionOperationInterface) !== $collection) {
continue;
}

$hydraOperations[] = $this->getHydraOperation($operation, $operation->getShortName(), $hydraPrefix);
}

return $hydraOperations;
Expand Down
4 changes: 0 additions & 4 deletions src/Hydra/Serializer/EntrypointNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ public function normalize(mixed $data, ?string $format = null, array $context =
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);

foreach ($resourceMetadata as $resource) {
if ($resource->getExtraProperties()['is_alternate_resource_metadata'] ?? false) {
continue;
}

foreach ($resource->getOperations() as $operation) {
$key = lcfirst($resource->getShortName());
if (true === $operation->getHideHydraOperation() || !$operation instanceof CollectionOperationInterface || isset($entrypoint[$key])) {
Expand Down
Loading