Skip to content

Commit

Permalink
api: upgrade api-platform/core to 3.2.1
Browse files Browse the repository at this point in the history
update api-plattform-allow-null-links.patch because of whitespace changes:
create a file ...._old.php with the repository version of the file

then: git diff --no-index api/vendor/api-platform/core/src/Hal/Serializer/ItemNormalizer_old.php api/vendor/api-platform/core/src/Hal/Serializer/ItemNormalizer.php

Add docs_formats because this must now be configured separately to enable
hal.
Do not support json as docs format, because this renders an error.
(It returns a 200 response, but the returned json contains a stacktrace).
  • Loading branch information
BacLuc committed Oct 21, 2023
1 parent 723d888 commit 1f735a2
Show file tree
Hide file tree
Showing 24 changed files with 65 additions and 61 deletions.
2 changes: 1 addition & 1 deletion api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"php": ">=8.1.0",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "3.1.20",
"api-platform/core": "3.2.1",
"composer/package-versions-deprecated": "1.11.99",
"cweagans/composer-patches": "1.7.3",
"doctrine/doctrine-bundle": "2.10.2",
Expand Down
19 changes: 10 additions & 9 deletions api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ api_platform:
jsonapi: [ 'application/vnd.api+json' ]
json: [ 'application/json' ]
html: [ 'text/html' ]
docs_formats:
jsonhal: [ 'application/hal+json' ]
jsonld: [ 'application/ld+json' ]
jsonapi: [ 'application/vnd.api+json' ]
html: [ 'text/html' ]
patch_formats:
json: [ 'application/merge-patch+json' ]
error_formats:
Expand Down
2 changes: 1 addition & 1 deletion api/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ services:
App\Serializer\Normalizer\TranslationConstraintViolationListNormalizer:
arguments:
- '@api_platform.hydra.normalizer.constraint_violation_list'
- '@api_platform.problem.normalizer.constraint_violation_list'
- '@api_platform.hal.normalizer.constraint_violation_list'

App\Serializer\SerializerContextBuilder:
decorates: 'api_platform.serializer.context_builder'
Expand Down
16 changes: 6 additions & 10 deletions api/patch/api-plattform-allow-null-links.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ Subject: [PATCH] hal allow null links

---
src/Hal/Serializer/ItemNormalizer.php | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/Hal/Serializer/ItemNormalizer.php b/src/Hal/Serializer/ItemNormalizer.php
index a6e485d178..824679ee6b 100644
--- a/src/Hal/Serializer/ItemNormalizer.php
+++ b/src/Hal/Serializer/ItemNormalizer.php
@@ -189,9 +189,6 @@ private function populateRelation(array $data, $object, ?string $format, array $
}
@@ -244,14 +244,12 @@ final class ItemNormalizer extends AbstractItemNormalizer

$attributeValue = $this->getAttributeValue($object, $relation['name'], $format, $childContext);

$attributeValue = $this->getAttributeValue($object, $relation['name'], $format, $context);
- if (empty($attributeValue)) {
- continue;
- }

$relationName = $relation['name'];
if ($this->nameConverter) {
@@ -200,8 +197,10 @@ private function populateRelation(array $data, $object, ?string $format, array $

-
if ('one' === $relation['cardinality']) {
if ('links' === $type) {
- $data[$key][$relationName]['href'] = $this->getRelationIri($attributeValue);
Expand All @@ -33,4 +29,4 @@ index a6e485d178..824679ee6b 100644
+ }
}

$data[$key][$relationName] = $attributeValue;
$data[$key][$relationName] = $attributeValue;
2 changes: 1 addition & 1 deletion api/src/Doctrine/Filter/ContentNodePeriodFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Doctrine\Filter;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Operation;
use App\Entity\Activity;
use App\Entity\ContentNode;
Expand Down
2 changes: 1 addition & 1 deletion api/src/Doctrine/Filter/MaterialItemPeriodFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Doctrine\Filter;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Doctrine\Orm\Filter\AbstractFilter;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Operation;
use App\Entity\Activity;
use App\Entity\ContentNode\MaterialNode;
Expand Down
2 changes: 1 addition & 1 deletion api/src/EventListener/JWTCreatedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\EventListener;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Metadata\IriConverterInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
use Symfony\Bundle\SecurityBundle\Security;

Expand Down
2 changes: 1 addition & 1 deletion api/src/Metadata/Resource/Factory/UriTemplateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace App\Metadata\Resource\Factory;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Api\UrlGeneratorInterface;
use ApiPlatform\Exception\ResourceClassNotFoundException;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\HttpOperation;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Serializer\Normalizer;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Api\ResourceClassResolverInterface;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
Expand Down
2 changes: 1 addition & 1 deletion api/src/Serializer/Normalizer/ContentTypeNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Serializer\Normalizer;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Metadata\IriConverterInterface;
use App\Entity\ContentType;
use App\Metadata\Resource\Factory\UriTemplateFactory;
use Rize\UriTemplate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
namespace App\Serializer\Normalizer;

use ApiPlatform\Api\FilterInterface;
use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Api\UrlGeneratorInterface;
use ApiPlatform\Doctrine\Common\PropertyHelperTrait;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Exception\ResourceClassNotFoundException;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use App\Entity\BaseEntity;
use App\Metadata\Resource\Factory\UriTemplateFactory;
use App\Metadata\Resource\OperationHelper;
use App\Util\ClassInfoTrait;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\Mapping\ClassMetadata;
use Rize\UriTemplate;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
Expand Down Expand Up @@ -89,9 +90,9 @@ public function __construct(
private UriTemplateFactory $uriTemplateFactory,
private RouterInterface $router,
private IriConverterInterface $iriConverter,
private ManagerRegistry $managerRegistry,
private readonly EntityManagerInterface $entityManager,
private ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
private PropertyAccessorInterface $propertyAccessor
private PropertyAccessorInterface $propertyAccessor,
) {}

public function supportsNormalization($data, $format = null, array $context = []): bool {
Expand Down Expand Up @@ -226,8 +227,8 @@ protected function normalizeUriParam($param): string {
return $param;
}

protected function getManagerRegistry(): ManagerRegistry {
return $this->managerRegistry;
protected function getClassMetadata(string $resourceClass): ClassMetadata {
return $this->entityManager->getClassMetadata($resourceClass);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class TranslationConstraintViolationListNormalizer implements NormalizerInterface {
public function __construct(
private readonly AbstractConstraintViolationListNormalizer $hydraNormalizer,
private readonly AbstractConstraintViolationListNormalizer $problemNormalizer,
private readonly AbstractConstraintViolationListNormalizer $halNormalizer,
private readonly TranslationInfoOfConstraintViolation $translationInfoOfConstraintViolation,
private readonly TranslateToAllLocalesService $translateToAllLocalesService
) {}
Expand All @@ -33,7 +33,7 @@ public function normalize(mixed $object, string $format = null, array $context =

/** @var ConstraintViolationList $object */
foreach ($object as $violation) {
foreach ($result['violations'] as &$resultItem) {
foreach ($result as &$resultItem) {
$code = $resultItem['code'] ?? null;
$propertyPath = $resultItem['propertyPath'];
$message = $resultItem['message'] ?? null;
Expand Down Expand Up @@ -80,6 +80,6 @@ public function getSupportedTypes(?string $format): array {
}

private function getNormalizerCollection(): ArrayCollection {
return new ArrayCollection([$this->hydraNormalizer, $this->problemNormalizer]);
return new ArrayCollection([$this->hydraNormalizer, $this->halNormalizer]);
}
}
2 changes: 1 addition & 1 deletion api/src/Serializer/Normalizer/UriTemplateNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Serializer\Normalizer;

use ApiPlatform\Api\UrlGeneratorInterface;
use ApiPlatform\Metadata\UrlGeneratorInterface;
use App\Metadata\Resource\Factory\UriTemplateFactory;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\String\Inflector\EnglishInflector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function create(string $resourceClass, string $property, array $options =
$apiProperty->isInitializable(),
$apiProperty->getIris(),
$apiProperty->getGenId(),
$apiProperty->getUriTemplate(),
$apiProperty->getExtraProperties()
);
}
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Api/ECampApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Tests\Api;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\JsonSchema\Schema;
use ApiPlatform\JsonSchema\SchemaFactoryInterface;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Doctrine/Filter/ContentNodePeriodFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Tests\Doctrine\Filter;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\IriConverterInterface;
use App\Doctrine\Filter\ContentNodePeriodFilter;
use App\Entity\ContentNode;
use App\Entity\Period;
Expand Down
2 changes: 1 addition & 1 deletion api/tests/Doctrine/Filter/MaterialItemPeriodFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Tests\Doctrine\Filter;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\IriConverterInterface;
use App\Doctrine\Filter\MaterialItemPeriodFilter;
use App\Entity\MaterialItem;
use App\Entity\Period;
Expand Down
2 changes: 1 addition & 1 deletion api/tests/EventListener/JWTCreatedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Tests\EventListener;

use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Metadata\IriConverterInterface;
use App\Entity\User;
use App\EventListener\JWTCreatedListener;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTCreatedEvent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Tests\Integration\Serializer\Normalizer;

use ApiPlatform\Hal\Serializer\ConstraintViolationListNormalizer as HalConstraintViolationListNormalizer;
use ApiPlatform\Hydra\Serializer\ConstraintViolationListNormalizer as HydraConstraintViolationListNormalizer;
use ApiPlatform\Problem\Serializer\ConstraintViolationListNormalizer as JsonProblemConstraintViolationListNormalizer;
use ApiPlatform\Symfony\Bundle\Test\ApiTestAssertionsTrait;
use App\Entity\CampCollaboration;
use App\Serializer\Normalizer\TranslationConstraintViolationListNormalizer;
Expand Down Expand Up @@ -51,7 +51,7 @@ public function testAddsTranslationKeyAndParameters(string $format) {
[]
);

self::assertArraySubset(['violations' => [
self::assertArraySubset([
[
'i18n' => [
'key' => 'app.validator.allowtransition.assertallowtransitions',
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testAddsTranslationKeyAndParameters(string $format) {
'parameters' => [],
],
],
]], $result);
], $result);
}

/**
Expand All @@ -99,7 +99,7 @@ public function testAddsTranslations(string $format) {
[]
);

self::assertArraySubset(['violations' => [
self::assertArraySubset([
[
'i18n' => [
'translations' => [
Expand Down Expand Up @@ -144,12 +144,12 @@ public function testAddsTranslations(string $format) {
],
],
],
]], $result);
], $result);
}

public static function getFormats() {
$hydra = HydraConstraintViolationListNormalizer::FORMAT;
$problem = JsonProblemConstraintViolationListNormalizer::FORMAT;
$problem = HalConstraintViolationListNormalizer::FORMAT;

return [
$hydra => [$hydra],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace App\Tests\Metadata\Resource\Factory;

use ApiPlatform\Api\FilterInterface;
use ApiPlatform\Api\IriConverterInterface;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\IriConverterInterface;
use ApiPlatform\Metadata\Operations;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
Expand Down
Loading

0 comments on commit 1f735a2

Please sign in to comment.