Skip to content

Commit

Permalink
fix(symfony): no read should not throw on wrong uri variables
Browse files Browse the repository at this point in the history
fixes #6358
  • Loading branch information
soyuka committed May 8, 2024
1 parent 04474e4 commit 2edf04c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Serializer/SerializerContextBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function createFromRequest(Request $request, bool $normalization, ?array
}
}

if (($options = $operation?->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
if (null === $context['output'] && ($options = $operation?->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
$context['force_resource_class'] = $operation->getClass();
}

Expand Down
8 changes: 7 additions & 1 deletion src/State/Processor/SerializeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ public function process(mixed $data, Operation $operation, array $uriVariables =
// @see ApiPlatform\State\Processor\RespondProcessor
$context['original_data'] = $data;

$class = $operation->getClass();
if ($request->attributes->get('_api_resource_class') !== $operation->getClass()) {
$class = $request->attributes->get('_api_resource_class');
trigger_deprecation('api-platform/core', '3.3', 'The resource class on the router is not the same as the operation\'s class which leads to wrong behaviors. Prefer using "stateOptions" if you need to change the entity class.');
}

$serializerContext = $this->serializerContextBuilder->createFromRequest($request, true, [
'resource_class' => $operation->getClass(),
'resource_class' => $class,
'operation' => $operation,
]);

Expand Down

0 comments on commit 2edf04c

Please sign in to comment.