Skip to content
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

With api platform, State Processor returns input DTO regardless of output class or normalization context #17

Open
rnbw-spctrm opened this issue Sep 12, 2024 · 0 comments

Comments

@rnbw-spctrm
Copy link

rnbw-spctrm commented Sep 12, 2024

The Api Platform 3 Part 3: Custom Resource course leads to an incomplete setup when using a custom resource with a different input and output format (either distinct DTO classes or when using serialization groups). The 'output' property and the 'normalizationContext' on both the resource and operation are ignored, so POST requests will return the input DTO.

I solved this by mapping to the output DTO and returning this object at the end of the process method in the state processor.

...

class DtoToEntityStateProcessor implements ProcessorInterface
{
    ...
    
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
    {
        ...

        return $this->microMapper->map($entity, OutputDto::class, [
            MicroMapperInterface::MAX_DEPTH => 1
        ]);
    }

I am posting this here in case anyone runs into the same issue, as this took me multiple days to track down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant