-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[API] allow extending and overwrite api in yaml + test #12693
Conversation
SirDomin
commented
Jun 7, 2021
Q | A |
---|---|
Branch? | master |
Bug fix? | no |
New feature? | yes |
BC breaks? | no |
Deprecations? | no |
Related tickets | |
License | MIT |
cbfb8d9
to
4a7264b
Compare
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
'%sylius.model.zone.class%': | ||
collectionOperations: | ||
admin_get (unset): ~ | ||
admin_post (unset): ~ |
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.
👎 operations should not be merged but replaced and it'd solve everyone's issues.
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.
Do you mean, that we should replace the whole configuration of the resource? That would make sense. But the issue is, that for many cases Order would be replaced with the new configuration and once the configuration is replaced you will never receive upstream changes or features - therefore BC may be challenging on our side and it may raise some issues on the user side to determine what has changed in core and apply changes to his/hers app. The problem would be smaller if we would be able to declare more granular resources. It would be perfect if one entity could be represented by several resources. For example, one order resource could be represented as shop order, admin order, and cart. Once we would reduce size of configuration files replacement seems to be much more viable option
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.
Yes really interesting, I hope that the next version of API Platform will help you to do so in an less constricting way! Btw are you doing Archtectural Decision Records for these kind of things?
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.
For sure we should add for this 👍
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
$resultingConfig = []; | ||
|
||
foreach ($configs as $config) { | ||
foreach ($config as $newKey => $newValue) { |
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 really think that this is a bad idea, replacing the configuration over merging would be easier and more obvious.
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.
As it's quite a complicated and potentially an error-prone feature, maybe it would be good to add at least one more test to unset some custom operation, something like shop_select_shipping_method
? I would personally feel more secured if we also check this feature on a non-crud operation 🖖
src/Sylius/Bundle/ApiBundle/test/src/Tests/SyliusRouteDisableTest.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
3a54281
to
e933156
Compare
e933156
to
d2b7f0d
Compare
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.
For me, there are some missing tests for cases like overwriting the existing endpoint by changing it (not only unsetting) or checking that endpoints from the base configuration are not replaced by for example adding a new one.
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/ResourceMetadataPropertyValueResolver.php
Outdated
Show resolved
Hide resolved
7f020cb
to
384f99d
Compare
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/ResourceMetadataPropertyValueResolver.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/ResourceMetadataPropertyValueResolver.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/ResourceMetadataPropertyValueResolver.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/spec/ApiPlatform/ConfigMergeManagerSpec.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/spec/ApiPlatform/ConfigMergeManagerSpec.php
Outdated
Show resolved
Hide resolved
namespace Sylius\Bundle\ApiBundle\ApiPlatform; | ||
|
||
/** @experimental */ | ||
class ApiResourceConfigurationMerger implements ApiResourceConfigurationMergerInterface |
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.
class ApiResourceConfigurationMerger implements ApiResourceConfigurationMergerInterface | |
final class ApiResourceConfigurationMerger implements ApiResourceConfigurationMergerInterface |
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.
im unable to write tests for it when its final (same with ResourceMetadataPropertyValueResolver)
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.
You should use interface in specs
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata; | ||
|
||
/** @experimental */ | ||
class ResourceMetadataPropertyValueResolver implements ResourceMetadataPropertyValueResolverInteface |
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.
class ResourceMetadataPropertyValueResolver implements ResourceMetadataPropertyValueResolverInteface | |
final class ResourceMetadataPropertyValueResolver implements ResourceMetadataPropertyValueResolverInteface |
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/ApiPlatform/Factory/MergingExtractorResourceMetadataFactory.php
Outdated
Show resolved
Hide resolved
src/Sylius/Bundle/ApiBundle/spec/ApiPlatform/ResourceMetadataPropertyValueResolverSpec.php
Outdated
Show resolved
Hide resolved
|
||
<service id="Sylius\Bundle\ApiBundle\ApiPlatform\ApiResourceConfigurationMerger" /> | ||
|
||
<service id="Sylius\Bundle\ApiBundle\ApiPlatform\ResourceMetadataPropertyValueResolver" > |
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.
<service id="Sylius\Bundle\ApiBundle\ApiPlatform\ResourceMetadataPropertyValueResolver" > | |
<service id="Sylius\Bundle\ApiBundle\ApiPlatform\ResourceMetadataPropertyValueResolver"> |
$this->beConstructedWith($apiResourceConfigurationMerger); | ||
} | ||
|
||
function it_returns_merged_configs(ApiResourceConfigurationMerger $apiResourceConfigurationMerger): void |
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.
function it_returns_merged_configs(ApiResourceConfigurationMerger $apiResourceConfigurationMerger): void | |
function it_returns_merged_configs(ApiResourceConfigurationMergerInterface $apiResourceConfigurationMerger): void |
namespace Sylius\Bundle\ApiBundle\ApiPlatform; | ||
|
||
/** @experimental */ | ||
class ApiResourceConfigurationMerger implements ApiResourceConfigurationMergerInterface |
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.
You should use interface in specs
Thank you, @SirDomin! 🥇 |
This PR was merged into the 1.11-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | docs for #12693 | License | MIT <!-- - Bug fixes must be submitted against the 1.9 or 1.10 branch (the lowest possible) - Features and deprecations must be submitted against the master 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 --> Commits ------- f59c7cc add docs about yaml 0f9e0f8 pr-fix 36ec10f add info about overwriting operation
This PR was merged into the 1.11-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | #12693 | License | MIT <!-- - Bug fixes must be submitted against the 1.9 or 1.10 branch (the lowest possible) - Features and deprecations must be submitted against the master 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 --> Commits ------- 285edea add final to clssess, cs fixes
This PR was merged into the 1.11-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | Sylius/Sylius#12693 | License | MIT <!-- - Bug fixes must be submitted against the 1.9 or 1.10 branch (the lowest possible) - Features and deprecations must be submitted against the master 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 --> Commits ------- 285edea63378e3a8746e710f05927ec4ad461e34 add final to clssess, cs fixes
This PR was merged into the 1.11 branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | 1.11 | | Bug fix? | yes | | New feature? | no | | BC breaks? | no | | Deprecations? | no | | Related tickets | fixes #14268 | | License | MIT | This PR removes the `%kernel.project_dir%/config/api_platform` mapping path that was introduced in #12693. In API Platform 2.6 users' mapping configuration is overwritten with bundles' mapping. Because of it, developers cannot override resources in `config/api_platform` as Sylius overrides users' resources placed in `config/api_platform`. It's already fixed in APIP 2.7 but for now, this configuration doesn't work as intended. We haven't noticed in unit tests that it breaks resource overriding because we have a distinction between `config/api_platform` and `config/api_resource`, where `api_resource` can override resources while `api_platform` can't. This distinction is something reasonable but for testing purposes, we should keep everything in one directory because it makes possible to test this bug. Commits ------- fe1d660 [API] Remove mapping path from configuration