diff --git a/config/services.yaml b/config/services.yaml index e72b564d638..af20839e59d 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -230,8 +230,8 @@ services: tags: [{ name: 'serializer.normalizer', priority: 1 }] App\Normalizer\ConstraintViolationListNormalizer: - decorates: 'serializer.normalizer.constraint_violation_list' - tags: [{ name: 'serializer.normalizer', priority: -1024 }] + decorates: 'api_platform.problem.normalizer.validation_exception' + tags: [{ name: 'serializer.normalizer', priority: -800 }] arguments: - '@serializer.name_converter.metadata_aware' diff --git a/src/Adhesion/Request/MembershipRequest.php b/src/Adhesion/Request/MembershipRequest.php index 10976e7d689..8221811aa5e 100644 --- a/src/Adhesion/Request/MembershipRequest.php +++ b/src/Adhesion/Request/MembershipRequest.php @@ -41,7 +41,6 @@ class MembershipRequest implements DonationRequestInterface #[Assert\NotBlank] public ?string $nationality = null; - #[Assert\Type('bool')] public ?bool $exclusiveMembership = null; #[Assert\AtLeastOneOf([ diff --git a/src/Api/Filter/AbstractScopeFilter.php b/src/Api/Filter/AbstractScopeFilter.php index 01de625eed6..259ce30215a 100644 --- a/src/Api/Filter/AbstractScopeFilter.php +++ b/src/Api/Filter/AbstractScopeFilter.php @@ -87,7 +87,7 @@ public function setSecurity(Security $security): void protected function getAllowedOperationNames(string $resourceClass): array { - return ['{uuid}_get', '{uuid}.{_format}_get', '_get_collection']; + return ['{uuid}_get', '{uuid}{._format}_get', '_get_collection']; } private function isValidOperation(?Operation $operation): bool diff --git a/src/Api/Filter/ScopeVisibilityFilter.php b/src/Api/Filter/ScopeVisibilityFilter.php index e9988d6f9b4..b542166082a 100644 --- a/src/Api/Filter/ScopeVisibilityFilter.php +++ b/src/Api/Filter/ScopeVisibilityFilter.php @@ -96,6 +96,6 @@ protected function getAllowedOperationNames(string $resourceClass): array return ['_api_/v3/jecoute/news/{uuid}_get', '_api_/v3/jecoute/news_get_collection']; } - return ['{uuid}_get', '{uuid}.{_format}_get', '_get_collection']; + return ['{uuid}_get', '{uuid}{._format}_get', '_get_collection']; } } diff --git a/src/Api/IriConverterDecorator.php b/src/Api/IriConverterDecorator.php new file mode 100644 index 00000000000..00fa74e6e87 --- /dev/null +++ b/src/Api/IriConverterDecorator.php @@ -0,0 +1,36 @@ +decorated->getIriFromResource(resource: $context['resource_class'], context: ['uri_variables' => ['uuid' => $iri]]); + } elseif (is_a($context['resource_class'], BaseEventCategory::class, true)) { + $iri = $this->decorated->getIriFromResource(resource: $context['resource_class'], context: ['uri_variables' => ['slug' => $iri]]); + } + + return $this->decorated->getResourceFromIri($iri, $context, $operation); + } + + public function getIriFromResource( + object|string $resource, + int $referenceType = UrlGeneratorInterface::ABS_PATH, + ?Operation $operation = null, + array $context = [], + ): ?string { + return $this->decorated->getIriFromResource($resource, $referenceType, $operation, $context); + } +} diff --git a/src/Api/Listener/AdherentListener.php b/src/Api/Listener/AdherentListener.php index a18fbe7a090..a58f2098a96 100644 --- a/src/Api/Listener/AdherentListener.php +++ b/src/Api/Listener/AdherentListener.php @@ -34,7 +34,7 @@ public function onPostWrite(ViewEvent $viewEvent): void if ( !\in_array($request->getMethod(), [Request::METHOD_POST, Request::METHOD_PUT]) - || '_api_/adherents/{uuid}/elect_put' !== $request->attributes->get('_api_operation_name') + || '_api_/v3/adherents/{uuid}/elect_put' !== $request->attributes->get('_api_operation_name') ) { return; } diff --git a/src/Api/Listener/PostEventInscriptionEditListener.php b/src/Api/Listener/PostEventInscriptionEditListener.php index 481ebd53c0f..b5595067a95 100644 --- a/src/Api/Listener/PostEventInscriptionEditListener.php +++ b/src/Api/Listener/PostEventInscriptionEditListener.php @@ -26,7 +26,7 @@ public function onEventInscriptionChange(RequestEvent $requestEvent): void { $request = $requestEvent->getRequest(); - if ('_api_/event_inscriptions/{uuid}.{_format}_put' !== $request->attributes->get('_api_operation_name')) { + if ('_api_/event_inscriptions/{uuid}{._format}_put' !== $request->attributes->get('_api_operation_name')) { return; } diff --git a/src/Controller/Api/UserController.php b/src/Controller/Api/UserController.php index 9a71b5a558f..3ff5aea1787 100644 --- a/src/Controller/Api/UserController.php +++ b/src/Controller/Api/UserController.php @@ -2,7 +2,6 @@ namespace App\Controller\Api; -use ApiPlatform\Problem\Serializer\ConstraintViolationListNormalizer; use App\AdherentProfile\Password; use App\Entity\Adherent; use App\Entity\AdherentResetPasswordToken; @@ -86,10 +85,7 @@ public function createPassword( $errors = $validator->validate($password); if (0 !== $errors->count()) { - return JsonResponse::fromJsonString( - $serializer->serialize($errors, ConstraintViolationListNormalizer::FORMAT), - Response::HTTP_BAD_REQUEST - ); + return $this->json($errors, Response::HTTP_BAD_REQUEST); } try { diff --git a/src/Entity/Action/Action.php b/src/Entity/Action/Action.php index c3ae8dd55f8..d5b33431e10 100644 --- a/src/Entity/Action/Action.php +++ b/src/Entity/Action/Action.php @@ -55,16 +55,17 @@ uriTemplate: '/v3/actions/{uuid}', security: "object.getAuthor() == user or user.hasDelegatedFromUser(object.getAuthor(), 'actions')" ), - new Put( + new HttpOperation( + method: 'PUT', uriTemplate: '/v3/actions/{uuid}/cancel', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: CancelActionController::class ), new HttpOperation( method: 'POST|DELETE', uriTemplate: '/v3/actions/{uuid}/register', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: RegisterController::class ), diff --git a/src/Entity/AdherentMessage/AbstractAdherentMessage.php b/src/Entity/AdherentMessage/AbstractAdherentMessage.php index 4065fdbac0d..3e4c5331bde 100644 --- a/src/Entity/AdherentMessage/AbstractAdherentMessage.php +++ b/src/Entity/AdherentMessage/AbstractAdherentMessage.php @@ -9,6 +9,7 @@ use ApiPlatform\Metadata\Delete; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Put; use App\AdherentMessage\AdherentMessageDataObject; @@ -64,27 +65,31 @@ normalizationContext: ['groups' => ['message_read']], security: "is_granted('REQUEST_SCOPE_GRANTED', 'messages') and (object.getAuthor() == user or user.hasDelegatedFromUser(object.getAuthor(), 'messages'))" ), - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/v3/adherent_messages/{uuid}/send', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: SendAdherentMessageController::class ), - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/v3/adherent_messages/{uuid}/send-test', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: SendTestAdherentMessageController::class ), - new Put( + new HttpOperation( + method: 'PUT', uriTemplate: '/v3/adherent_messages/{uuid}/filter', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: UpdateAdherentMessageFilterController::class ), - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/v3/adherent_messages/{uuid}/duplicate', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: DuplicateMessageController::class ), diff --git a/src/Entity/ElectedRepresentative/ElectedRepresentative.php b/src/Entity/ElectedRepresentative/ElectedRepresentative.php index 0ee54232d3b..ad868cb885b 100644 --- a/src/Entity/ElectedRepresentative/ElectedRepresentative.php +++ b/src/Entity/ElectedRepresentative/ElectedRepresentative.php @@ -131,7 +131,7 @@ class ElectedRepresentative implements EntityAdherentBlameableInterface, EntityA */ #[Groups(['elected_representative_write', 'elected_representative_read'])] #[ORM\Column(type: 'boolean', options: ['default' => false])] - private $hasFollowedTraining = false; + public bool $hasFollowedTraining = false; /** * Mailchimp unsubscribed date diff --git a/src/Entity/ElectedRepresentative/Mandate.php b/src/Entity/ElectedRepresentative/Mandate.php index 3299e4ae323..4d7ca429307 100644 --- a/src/Entity/ElectedRepresentative/Mandate.php +++ b/src/Entity/ElectedRepresentative/Mandate.php @@ -63,7 +63,7 @@ class Mandate */ #[Groups(['elected_mandate_write', 'elected_mandate_read', 'elected_representative_read'])] #[ORM\Column(type: 'boolean', options: ['default' => false])] - private $isElected; + public $isElected; /** * @var Zone|null diff --git a/src/Entity/Event/BaseEvent.php b/src/Entity/Event/BaseEvent.php index b2f910339be..396717ef9f3 100644 --- a/src/Entity/Event/BaseEvent.php +++ b/src/Entity/Event/BaseEvent.php @@ -98,16 +98,17 @@ new HttpOperation( method: 'POST|DELETE', uriTemplate: '/v3/events/{uuid}/subscribe', - defaults: ['_api_receive' => false], requirements: ['uuid' => '%pattern_uuid%'], controller: SubscribeAsAdherentController::class, - security: 'is_granted(\'ROLE_USER\')' + security: 'is_granted(\'ROLE_USER\')', + deserialize: false ), - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/events/{uuid}/subscribe', - defaults: ['_api_receive' => false], requirements: ['uuid' => '%pattern_uuid%'], - controller: SubscribeAsAnonymousController::class + controller: SubscribeAsAnonymousController::class, + deserialize: false ), new HttpOperation( method: 'POST|DELETE', @@ -117,11 +118,12 @@ security: "is_granted('REQUEST_SCOPE_GRANTED', 'events') and is_granted('CAN_MANAGE_EVENT', request.attributes.get('data'))", deserialize: false ), - new Put( + new HttpOperation( + method: 'PUT', uriTemplate: '/v3/events/{uuid}/cancel', - defaults: ['_api_receive' => false], requirements: ['uuid' => '%pattern_uuid%'], - controller: CancelEventController::class + controller: CancelEventController::class, + deserialize: false ), new GetCollection( uriTemplate: '/v3/events', diff --git a/src/Entity/Jecoute/JemarcheDataSurvey.php b/src/Entity/Jecoute/JemarcheDataSurvey.php index 1810e68a268..3004f9b551a 100644 --- a/src/Entity/Jecoute/JemarcheDataSurvey.php +++ b/src/Entity/Jecoute/JemarcheDataSurvey.php @@ -4,6 +4,7 @@ use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\Post; use App\Controller\Api\Jecoute\JemarcheDataSurveyKpiController; use App\Controller\Api\Jecoute\JemarcheDataSurveyReplyController; @@ -22,9 +23,10 @@ #[ApiResource( operations: [ - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/v3/jemarche_data_surveys/{uuid}/reply', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: JemarcheDataSurveyReplyController::class, normalizationContext: ['groups' => ['data_survey_read']], diff --git a/src/Entity/Jecoute/Region.php b/src/Entity/Jecoute/Region.php index c1055d5b184..73f9141bb73 100644 --- a/src/Entity/Jecoute/Region.php +++ b/src/Entity/Jecoute/Region.php @@ -111,7 +111,6 @@ class Region /** * @var bool */ - #[Assert\Type('bool')] #[ORM\Column(type: 'boolean', options: ['default' => true])] private $enabled; diff --git a/src/Entity/Jecoute/Riposte.php b/src/Entity/Jecoute/Riposte.php index 2752e0231da..0e7f3607052 100644 --- a/src/Entity/Jecoute/Riposte.php +++ b/src/Entity/Jecoute/Riposte.php @@ -6,6 +6,7 @@ use ApiPlatform\Metadata\Delete; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Put; use App\Controller\Api\Jecoute\IncrementRiposteStatsCounterController; @@ -39,12 +40,13 @@ uriTemplate: '/v3/ripostes/{uuid}', requirements: ['uuid' => '%pattern_uuid%'] ), - new Put( + new HttpOperation( + method: 'PUT', uriTemplate: '/v3/ripostes/{uuid}/action/{action}', - defaults: ['_api_receive' => false], requirements: ['uuid' => '%pattern_uuid%'], controller: IncrementRiposteStatsCounterController::class, - security: "is_granted('REQUEST_SCOPE_GRANTED', 'ripostes') or (is_granted('ROLE_USER') and is_granted('ROLE_OAUTH_SCOPE_JEMARCHE_APP'))" + security: "is_granted('REQUEST_SCOPE_GRANTED', 'ripostes') or (is_granted('ROLE_USER') and is_granted('ROLE_OAUTH_SCOPE_JEMARCHE_APP'))", + deserialize: false, ), new GetCollection( uriTemplate: '/v3/ripostes', @@ -103,7 +105,6 @@ class Riposte implements AuthorInterface, IndexableEntityInterface /** * @var bool */ - #[Assert\Type('bool')] #[Groups(['riposte_list_read', 'riposte_read', 'riposte_write'])] #[ORM\Column(type: 'boolean', options: ['default' => true])] private $withNotification; @@ -111,7 +112,6 @@ class Riposte implements AuthorInterface, IndexableEntityInterface /** * @var bool */ - #[Assert\Type('bool')] #[Groups(['riposte_list_read', 'riposte_read', 'riposte_write'])] #[ORM\Column(type: 'boolean', options: ['default' => true])] private $enabled; diff --git a/src/Entity/MyTeam/MyTeam.php b/src/Entity/MyTeam/MyTeam.php index 12ec7115f1c..4f8445d5f6e 100644 --- a/src/Entity/MyTeam/MyTeam.php +++ b/src/Entity/MyTeam/MyTeam.php @@ -4,7 +4,7 @@ use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\GetCollection; -use ApiPlatform\Metadata\Post; +use ApiPlatform\Metadata\HttpOperation; use App\Api\Filter\MyTeamScopeFilter; use App\Controller\Api\MyTeam\InitializeMyTeamController; use App\Entity\Adherent; @@ -26,9 +26,10 @@ uriTemplate: '/v3/my_teams', normalizationContext: ['groups' => ['my_team_read_list']] ), - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/v3/my_teams', - defaults: ['_api_receive' => false], + deserialize: false, controller: InitializeMyTeamController::class ), ], diff --git a/src/Entity/Pap/Campaign.php b/src/Entity/Pap/Campaign.php index af1994d9d2c..6230d7a7cb9 100644 --- a/src/Entity/Pap/Campaign.php +++ b/src/Entity/Pap/Campaign.php @@ -60,7 +60,6 @@ ), new Get( uriTemplate: '/v3/pap_campaigns/{uuid}/questioners', - defaults: ['_api_receive' => false], requirements: ['uuid' => '%pattern_uuid%'], controller: GetPapCampaignQuestionersStatsController::class, security: "is_granted('REQUEST_SCOPE_GRANTED', ['pap_v2', 'pap'])" diff --git a/src/Entity/Pap/CampaignHistory.php b/src/Entity/Pap/CampaignHistory.php index bbe9e96396e..12994b10ef9 100644 --- a/src/Entity/Pap/CampaignHistory.php +++ b/src/Entity/Pap/CampaignHistory.php @@ -8,6 +8,7 @@ use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Put; use App\Api\Filter\AdherentIdentityFilter; @@ -42,9 +43,10 @@ requirements: ['uuid' => '%pattern_uuid%'], security: 'is_granted(\'ROLE_OAUTH_SCOPE_JEMARCHE_APP\') and object.getQuestioner() == user' ), - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/v3/pap_campaign_histories/{uuid}/reply', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: CampaignHistoryReplyController::class, normalizationContext: ['groups' => ['data_survey_read']] diff --git a/src/Entity/Phoning/Campaign.php b/src/Entity/Phoning/Campaign.php index 45016b4d83b..70624244c15 100644 --- a/src/Entity/Phoning/Campaign.php +++ b/src/Entity/Phoning/Campaign.php @@ -63,7 +63,6 @@ ), new Get( uriTemplate: '/v3/phoning_campaigns/{uuid}/callers', - defaults: ['_api_receive' => false], requirements: ['uuid' => '%pattern_uuid%'], controller: GetPhoningCampaignCallersStatsController::class, security: "is_granted('REQUEST_SCOPE_GRANTED', 'phoning_campaign')" diff --git a/src/Entity/Phoning/CampaignHistory.php b/src/Entity/Phoning/CampaignHistory.php index 80da23a8c06..66ea0a03f12 100644 --- a/src/Entity/Phoning/CampaignHistory.php +++ b/src/Entity/Phoning/CampaignHistory.php @@ -7,7 +7,7 @@ use ApiPlatform\Metadata\ApiFilter; use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\GetCollection; -use ApiPlatform\Metadata\Post; +use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\Put; use App\Api\Filter\AdherentIdentityFilter; use App\Controller\Api\Phoning\CampaignHistoryReplyController; @@ -37,9 +37,10 @@ requirements: ['uuid' => '%pattern_uuid%'], security: 'is_granted(\'IS_CAMPAIGN_HISTORY_CALLER\', object)' ), - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/v3/phoning_campaign_histories/{uuid}/reply', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: CampaignHistoryReplyController::class, normalizationContext: ['groups' => ['data_survey_read']] diff --git a/src/Entity/ProcurationV2/Request.php b/src/Entity/ProcurationV2/Request.php index 62a161b1047..c7d4e5cf78c 100644 --- a/src/Entity/ProcurationV2/Request.php +++ b/src/Entity/ProcurationV2/Request.php @@ -8,8 +8,8 @@ use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\Patch; -use ApiPlatform\Metadata\Post; use App\Api\Filter\OrTextSearchFilter; use App\Api\Filter\ProcurationZoneFilter; use App\Controller\Api\Procuration\GetMatchedProxiesController; @@ -42,15 +42,17 @@ requirements: ['uuid' => '%pattern_uuid%'], normalizationContext: ['groups' => ['procuration_request_read'], 'enable_tag_translator' => true] ), - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/requests/{uuid}/match', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: MatchRequestWithProxyController::class ), - new Post( + new HttpOperation( + method: 'POST', uriTemplate: '/requests/{uuid}/unmatch', - defaults: ['_api_receive' => false], + deserialize: false, requirements: ['uuid' => '%pattern_uuid%'], controller: UnmatchRequestAndProxyController::class ), diff --git a/src/Entity/VotingPlatform/Designation/Designation.php b/src/Entity/VotingPlatform/Designation/Designation.php index 9d47a53f46b..21e3d494565 100644 --- a/src/Entity/VotingPlatform/Designation/Designation.php +++ b/src/Entity/VotingPlatform/Designation/Designation.php @@ -7,6 +7,7 @@ use ApiPlatform\Metadata\ApiResource; use ApiPlatform\Metadata\Get; use ApiPlatform\Metadata\GetCollection; +use ApiPlatform\Metadata\HttpOperation; use ApiPlatform\Metadata\Post; use ApiPlatform\Metadata\Put; use App\Api\Filter\InZoneOfScopeFilter; @@ -54,12 +55,13 @@ security: "is_granted('REQUEST_SCOPE_GRANTED', 'designation')", validationContext: ['groups' => UpdateDesignationGroupGenerator::class] ), - new Put( + new HttpOperation( + method: 'PUT', uriTemplate: '/designations/{uuid}/cancel', - defaults: ['_api_receive' => false], requirements: ['uuid' => '%pattern_uuid%'], controller: CancelElectionController::class, - security: "is_granted('REQUEST_SCOPE_GRANTED', 'designation')" + security: "is_granted('REQUEST_SCOPE_GRANTED', 'designation')", + deserialize: false ), new GetCollection(normalizationContext: ['groups' => ['designation_list']]), new Post(validationContext: ['groups' => ['api_designation_write']]), @@ -273,7 +275,7 @@ class Designation implements EntityAdministratorBlameableInterface, EntityAdhere #[Groups(['designation_read', 'designation_list'])] #[ORM\Column(type: 'boolean', options: ['default' => false])] - private bool $isCanceled = false; + public bool $isCanceled = false; #[ORM\Column(nullable: true)] public ?string $alertTitle = null; diff --git a/src/Normalizer/CommitteeCandidacyDenormalizer.php b/src/Normalizer/CommitteeCandidacyDenormalizer.php index b68346ab6a2..69e921ac8de 100644 --- a/src/Normalizer/CommitteeCandidacyDenormalizer.php +++ b/src/Normalizer/CommitteeCandidacyDenormalizer.php @@ -50,6 +50,6 @@ public function getSupportedTypes(?string $format): array public function supportsDenormalization($data, string $type, ?string $format = null, array $context = []): bool { - return CommitteeCandidacy::class === $type && '_api_/committee_candidacies_post' === $context['operation_name']; + return CommitteeCandidacy::class === $type && '_api_/v3/committee_candidacies_post' === $context['operation_name']; } } diff --git a/src/Normalizer/ConstraintViolationListNormalizer.php b/src/Normalizer/ConstraintViolationListNormalizer.php index d0eca02fe06..813764a6dd7 100644 --- a/src/Normalizer/ConstraintViolationListNormalizer.php +++ b/src/Normalizer/ConstraintViolationListNormalizer.php @@ -2,6 +2,7 @@ namespace App\Normalizer; +use ApiPlatform\Validator\Exception\ConstraintViolationListAwareExceptionInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Validator\ConstraintViolationListInterface; @@ -14,6 +15,10 @@ public function __construct(private readonly NameConverterInterface $nameConvert public function normalize($object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null { + if ($object instanceof ConstraintViolationListAwareExceptionInterface) { + $object = $object->getConstraintViolationList(); + } + $violations = []; foreach ($object as $violation) { @@ -38,11 +43,12 @@ public function getSupportedTypes(?string $format): array return [ '*' => null, ConstraintViolationListInterface::class => true, + ConstraintViolationListAwareExceptionInterface::class => true, ]; } public function supportsNormalization($data, ?string $format = null, array $context = []): bool { - return $data instanceof ConstraintViolationListInterface; + return $data instanceof ConstraintViolationListInterface || $data instanceof ConstraintViolationListAwareExceptionInterface; } } diff --git a/src/Normalizer/DesignationDenormalizer.php b/src/Normalizer/DesignationDenormalizer.php index 815c7cf46a1..402348bb682 100644 --- a/src/Normalizer/DesignationDenormalizer.php +++ b/src/Normalizer/DesignationDenormalizer.php @@ -59,6 +59,6 @@ public function supportsDenormalization($data, string $type, ?string $format = n { return !isset($context[__CLASS__]) && is_a($type, Designation::class, true) - && \in_array($context['operation_name'] ?? null, ['_api_/designations.{_format}_post', '_api_/designations/{uuid}_put'], true); + && \in_array($context['operation_name'] ?? null, ['_api_/v3/designations{._format}_post', '_api_/v3/designations/{uuid}_put'], true); } } diff --git a/src/Normalizer/DocumentNormalizer.php b/src/Normalizer/DocumentNormalizer.php index e3e339d5dc2..19113989ee3 100644 --- a/src/Normalizer/DocumentNormalizer.php +++ b/src/Normalizer/DocumentNormalizer.php @@ -54,7 +54,7 @@ public function supportsNormalization($data, $format = null, array $context = [] private function getUrl(Document $document): string { return $this->urlGenerator->generate( - '_api_/documents/{uuid}/file_get', + '_api_/v3/documents/{uuid}/file_get', ['uuid' => $document->getUuid()], UrlGeneratorInterface::ABSOLUTE_URL ); diff --git a/src/Normalizer/ElectedMandateDenormalizer.php b/src/Normalizer/ElectedMandateDenormalizer.php index 2d91fe0d81b..8c896ccd5b2 100644 --- a/src/Normalizer/ElectedMandateDenormalizer.php +++ b/src/Normalizer/ElectedMandateDenormalizer.php @@ -54,6 +54,6 @@ public function supportsDenormalization($data, string $type, ?string $format = n { return !isset($context[__CLASS__]) && is_a($type, Mandate::class, true) - && '_api_/elected_mandates_post' === ($context['operation_name'] ?? null); + && '_api_/v3/elected_mandates_post' === ($context['operation_name'] ?? null); } } diff --git a/src/Normalizer/FormationNormalizer.php b/src/Normalizer/FormationNormalizer.php index c5db38558b0..91498141a6a 100644 --- a/src/Normalizer/FormationNormalizer.php +++ b/src/Normalizer/FormationNormalizer.php @@ -59,7 +59,7 @@ private function getUrl(Formation $formation): string $parameters['scope'] = $scope->getCode(); } - return $this->urlGenerator->generate('_api_/formations/{uuid}/file_get', $parameters, UrlGeneratorInterface::ABSOLUTE_URL); + return $this->urlGenerator->generate('_api_/v3/formations/{uuid}/file_get', $parameters, UrlGeneratorInterface::ABSOLUTE_URL); } private function getCurrentScope(): ?ScopeGeneratorInterface diff --git a/src/Normalizer/GeneralMeetingReportNormalizer.php b/src/Normalizer/GeneralMeetingReportNormalizer.php index 952b039dded..f635ea93bd8 100644 --- a/src/Normalizer/GeneralMeetingReportNormalizer.php +++ b/src/Normalizer/GeneralMeetingReportNormalizer.php @@ -59,7 +59,7 @@ private function getUrl(GeneralMeetingReport $generalMeetingReport): string $parameters['scope'] = $scope->getCode(); } - return $this->urlGenerator->generate('_api_/general_meeting_reports/{uuid}/file_get', $parameters, UrlGeneratorInterface::ABSOLUTE_URL); + return $this->urlGenerator->generate('_api_/v3/general_meeting_reports/{uuid}/file_get', $parameters, UrlGeneratorInterface::ABSOLUTE_URL); } private function getCurrentScope(): ?ScopeGeneratorInterface diff --git a/src/Normalizer/UpdateElectedMandateDenormalizer.php b/src/Normalizer/UpdateElectedMandateDenormalizer.php index 9aca6eb2b14..32812f11316 100644 --- a/src/Normalizer/UpdateElectedMandateDenormalizer.php +++ b/src/Normalizer/UpdateElectedMandateDenormalizer.php @@ -66,7 +66,7 @@ public function supportsDenormalization($data, string $type, ?string $format = n { return !isset($context[__CLASS__]) && is_a($type, Mandate::class, true) - && '_api_/elected_mandates/{uuid}_put' === ($context['operation_name'] ?? null); + && '_api_/v3/elected_mandates/{uuid}_put' === ($context['operation_name'] ?? null); } private function handleChanges( diff --git a/src/Procuration/Listener/CheckUpdatedStatusListener.php b/src/Procuration/Listener/CheckUpdatedStatusListener.php index 92534ed520a..ab66922ee5d 100644 --- a/src/Procuration/Listener/CheckUpdatedStatusListener.php +++ b/src/Procuration/Listener/CheckUpdatedStatusListener.php @@ -36,8 +36,8 @@ public function preDeserialize(RequestEvent $event): void $operationName = $request->attributes->get('_api_operation_name'); if (!\in_array($operationName, [ - '_api_/requests/{uuid}_patch', - '_api_/proxies/{uuid}_patch', + '_api_/v3/requests/{uuid}_patch', + '_api_/v3/proxies/{uuid}_patch', ], true)) { return; } diff --git a/src/Procuration/Listener/ProcurationSlotStatusActionListener.php b/src/Procuration/Listener/ProcurationSlotStatusActionListener.php index 8c60a32ffd3..7454d991de7 100644 --- a/src/Procuration/Listener/ProcurationSlotStatusActionListener.php +++ b/src/Procuration/Listener/ProcurationSlotStatusActionListener.php @@ -34,8 +34,8 @@ public function preDeserialize(RequestEvent $event): void $operationName = $request->attributes->get('_api_operation_name'); if (!\in_array($operationName, [ - '_api_/request_slots/{uuid}_put', - '_api_/proxy_slots/{uuid}_put', + '_api_/v3/request_slots/{uuid}_put', + '_api_/v3/proxy_slots/{uuid}_put', ], true)) { return; } @@ -55,8 +55,8 @@ public function preWrite(ViewEvent $event): void $operationName = $request->attributes->get('_api_operation_name'); if (!\in_array($operationName, [ - '_api_/request_slots/{uuid}_put', - '_api_/proxy_slots/{uuid}_put', + '_api_/v3/request_slots/{uuid}_put', + '_api_/v3/proxy_slots/{uuid}_put', ], true)) { return; } diff --git a/src/Procuration/Listener/ProcurationStatusActionListener.php b/src/Procuration/Listener/ProcurationStatusActionListener.php index 7ab5be85df4..591e1f64dcc 100644 --- a/src/Procuration/Listener/ProcurationStatusActionListener.php +++ b/src/Procuration/Listener/ProcurationStatusActionListener.php @@ -37,8 +37,8 @@ public function preDeserialize(RequestEvent $event): void $operationName = $request->attributes->get('_api_operation_name'); if (!\in_array($operationName, [ - '_api_/requests/{uuid}_patch', - '_api_/proxies/{uuid}_patch', + '_api_/v3/requests/{uuid}_patch', + '_api_/v3/proxies/{uuid}_patch', ], true)) { return; } @@ -66,8 +66,8 @@ public function preWrite(ViewEvent $event): void $operationName = $request->attributes->get('_api_operation_name'); if (!\in_array($operationName, [ - '_api_/requests/{uuid}_patch', - '_api_/proxies/{uuid}_patch', + '_api_/v3/requests/{uuid}_patch', + '_api_/v3/proxies/{uuid}_patch', ], true)) { return; }