-
-
Notifications
You must be signed in to change notification settings - Fork 923
feat(symfony): object mapper with state options #6801
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
Conversation
3a5efe5
to
6e954d5
Compare
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these provider and processor are Doctrine-specific. They should be moved to the Doctrine namespace and we can consider injecting the ObjectManager of ORM or ODM to retrieve the attached object.
Unless the new symfony/mapper component is able to use a factory to create the Entity class from the DTO. It would use the Id
field of the DTO to retreive the attached entity from the entity manager.
ff46774
to
280ee15
Compare
I'll fix the tests once the component is released |
d0d8e5a
to
f05422c
Compare
2b296b5
to
dfb5691
Compare
return $this->decorated->process($data, $operation, $uriVariables, $context); | ||
} | ||
|
||
return $this->objectMapper->map($this->decorated->process($this->objectMapper->map($data), $operation, $uriVariables, $context)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @soyuka , thanks for your work on this!
The map method is called without the $target parameter, even though we could extract the expected output class via:
$outputClass = $operation->getOutput()['class'] ?? null;
Would it make sense to pass this as the $target to improve mapping clarity ?
Same idea could apply to the mapping for ORM entity conversion — the target class could be extracted from stateOptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the mapping should be defined with the Map
attribute, as you could Map
and have a different output
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure the output matches the generated OpenAPI documentation, wouldn’t it make more sense to use the class specified in output, if it has been provided?
In cases where multiple target classes are possible, how should we determine which one should be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed I need to think about this but its best that your resource is your output. Could you please open a new issue with your use case ?
Still a few things left to be done but this is a first approach. This makes API Platform compatible with the Object Mapper component: symfony/symfony#51741
Demo:
Example: