Skip to content

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

Closed
esserj wants to merge 1 commit intoSylius:1.14from
Inventis:bugfix/merged-overrides-missing-operations
Closed

fix merging of api resource data fails or has existing data go missing#16146
esserj wants to merge 1 commit intoSylius:1.14from
Inventis:bugfix/merged-overrides-missing-operations

Conversation

@esserj
Copy link
Copy Markdown
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
Copy Markdown
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?


foreach ($newMetadata as $key => $value) {
if ('properties' === $key) {
if ($value === null) {
Copy link
Copy Markdown
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?

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 19, 2024

❌ Preview Environment deleted from Bunnyshell

Available commands:

  • 🚀 /bns:deploy to redeploy the environment

@esserj
Copy link
Copy Markdown
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
Copy Markdown
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.

@TheMilek TheMilek added Bug Confirmed bugs or bugfixes. and removed Potential Bug Potential bugs or bugfixes, that needs to be reproduced. labels Jul 17, 2024
@Rafikooo Rafikooo changed the base branch from 1.13 to 1.14 October 6, 2025 17:33
GSadee added a commit that referenced this pull request Jan 15, 2026
| Q               | A
|-----------------|-----
| Branch?         | 1.14 <!-- see the comment below -->
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.14 or 2.1 branch
 - Features and deprecations must be submitted against the 2.2 branch
 - Make sure that the correct base branch is set

To be sure you are not breaking any Backward Compatibilities, check the
documentation:

https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->
continuation of #16146
@GSadee
Copy link
Copy Markdown
Member

GSadee commented Jan 15, 2026

I'm closing the PR in favour of #18725

@GSadee GSadee closed this Jan 15, 2026
GSadee added a commit to Sylius/SyliusApiBundle that referenced this pull request Jan 20, 2026
| Q               | A
|-----------------|-----
| Branch?         | 1.14 <!-- see the comment below -->
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.14 or 2.1 branch
 - Features and deprecations must be submitted against the 2.2 branch
 - Make sure that the correct base branch is set

To be sure you are not breaking any Backward Compatibilities, check the
documentation:

https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->
continuation of Sylius/Sylius#16146
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. Bug Confirmed bugs or bugfixes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants