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

[API] allow extending and overwrite api in yaml + test #12693

Merged
merged 14 commits into from
Jun 22, 2021

Conversation

SirDomin
Copy link
Contributor

@SirDomin SirDomin commented Jun 7, 2021

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Related tickets
License MIT

@SirDomin SirDomin requested a review from a team as a code owner June 7, 2021 07:49
@probot-autolabeler probot-autolabeler bot added the API APIs related issues and PRs. label Jun 7, 2021
@SirDomin SirDomin changed the title [API] allow removing routes in yaml + test [API] allow extending and overwrite api in yaml + test Jun 7, 2021
@SirDomin SirDomin force-pushed the sylius-api-yaml-support branch 15 times, most recently from cbfb8d9 to 4a7264b Compare June 8, 2021 07:38
'%sylius.model.zone.class%':
collectionOperations:
admin_get (unset): ~
admin_post (unset): ~
Copy link

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.

Copy link
Member

@lchrusciel lchrusciel Jun 9, 2021

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

Copy link

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?

Copy link
Member

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 👍

$resultingConfig = [];

foreach ($configs as $config) {
foreach ($config as $newKey => $newValue) {
Copy link

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.

Copy link
Member

@Zales0123 Zales0123 left a 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 🖖

@SirDomin SirDomin force-pushed the sylius-api-yaml-support branch 7 times, most recently from 3a54281 to e933156 Compare June 10, 2021 12:06
Copy link
Member

@GSadee GSadee left a 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.

@probot-autolabeler probot-autolabeler bot added the Maintenance CI configurations, READMEs, releases, etc. label Jun 15, 2021
namespace Sylius\Bundle\ApiBundle\ApiPlatform;

/** @experimental */
class ApiResourceConfigurationMerger implements ApiResourceConfigurationMergerInterface
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class ApiResourceConfigurationMerger implements ApiResourceConfigurationMergerInterface
final class ApiResourceConfigurationMerger implements ApiResourceConfigurationMergerInterface

Copy link
Contributor Author

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)

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
class ResourceMetadataPropertyValueResolver implements ResourceMetadataPropertyValueResolverInteface
final class ResourceMetadataPropertyValueResolver implements ResourceMetadataPropertyValueResolverInteface


<service id="Sylius\Bundle\ApiBundle\ApiPlatform\ApiResourceConfigurationMerger" />

<service id="Sylius\Bundle\ApiBundle\ApiPlatform\ResourceMetadataPropertyValueResolver" >
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Member

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

@GSadee GSadee merged commit 86b80ff into Sylius:master Jun 22, 2021
@GSadee
Copy link
Member

GSadee commented Jun 22, 2021

Thank you, @SirDomin! 🥇

GSadee added a commit that referenced this pull request Jun 22, 2021
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
GSadee added a commit that referenced this pull request Jun 22, 2021
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
GSadee added a commit to Sylius/SyliusApiBundle that referenced this pull request Jun 22, 2021
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
GSadee added a commit that referenced this pull request Sep 13, 2022
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
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. Maintenance CI configurations, READMEs, releases, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants