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

fix merging of api resource data fails or has existing data go missing #16146

Open
wants to merge 1 commit into
base: 1.13
Choose a base branch
from

Conversation

esserj
Copy link
Contributor

@esserj esserj commented Apr 19, 2024

in case certain xml keys are missing from extending config like properties, item opteration, collection operations or resources

Q A
Branch? 1.13 - i know it is a bugfix, but the merger tests are missing from 1.12
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets /
License MIT

Basically what happens is that when you define api extension configuration through app (or multiple bundles)
you have to set at least 1 property in the file, oven though you do not want to make any changes (potentially overriding any future changes to it)
and you have to explicitly set every operation type (itemOperations, collectionOperations, resourceOperations) explictly
like <itemOperations /> etc or you will end up (based on order of execution) with eg default item operation configuration from api platform, or subresouce configation goes mising (e.g order override caused order adjustment subresource config from going awol)

in case certain xml keys are missing from extending config
like properties, item opteration, collection operations or resources
@esserj esserj requested review from a team as code owners April 19, 2024 07:50
@probot-autolabeler probot-autolabeler bot added the API APIs related issues and PRs. label Apr 19, 2024
@esserj esserj changed the title fix merging of data fails or has existing data go missing fix merging of api resource data fails or has existing data go missing Apr 19, 2024
$this->properties[$resourceClass],
$resourceMetadata['properties'],
$this->properties[$resourceClass] ?? [],
$resourceMetadata['properties'] ?? [],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null cannot be merged with []
Maybe adjusting \Sylius\Bundle\ApiBundle\ApiPlatform\Metadata\MergingXmlExtractor::buildResource properties to not default to null is better?

@@ -23,6 +23,10 @@ public function merge(array $oldMetadata, array $newMetadata): array

foreach ($newMetadata as $key => $value) {
if ('properties' === $key) {
if ($value === null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe adjusting \Sylius\Bundle\ApiBundle\ApiPlatform\Metadata\MergingXmlExtractor::buildResource properties is better?

Copy link

Bunnyshell Preview Environment deployed

It will be automatically stopped in 4 hours.

Use the command /bns:start to start it if it's stopped.

Component Endpoints
mailhog https://mailhog-fjg43l.bunnyenv.com/
php https://store-fjg43l.bunnyenv.com/

Available commands:

  • /bns:stop to stop the environment
  • /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@esserj
Copy link
Contributor Author

esserj commented Apr 19, 2024

this may break api's that accidentally exposed itemOperations by not defining them in extending files
as api-platform would have turned them into default operation endpoints (which depending on the endpoint) could have exposed admin only resource modification

@GSadee GSadee added the Potential Bug Potential bugs or bugfixes, that needs to be reproduced. label Apr 22, 2024
@GSadee
Copy link
Member

GSadee commented Apr 22, 2024

Hi @esserj and thank you for your contribution.
Indeed, the current merging behaviour of arrays when the data is not configured in the overwritten file can be confusing and it needs to be improved. Your solution potentially looks OK, although it does change the current behaviour. So, we would need to think through all possible scenarios for overwriting operations/properties/etc and test them in PHPUnit tests accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API APIs related issues and PRs. Potential Bug Potential bugs or bugfixes, that needs to be reproduced.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants