-
-
Notifications
You must be signed in to change notification settings - Fork 949
[RFC] [WIP] Offer post, delete and put subresource #2598
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
[RFC] [WIP] Offer post, delete and put subresource #2598
Conversation
601501e to
69fe295
Compare
|
It looks like that there is a bc breaking change in |
|
#2594 I'll bring this onto master today |
cb9f531 to
99f8ad2
Compare
172aeff to
7f87d6c
Compare
ebe2d51 to
7d11860
Compare
7d11860 to
b39d3ab
Compare
|
@torreytsui did you see that there is already a PR for this feature? #2428 |
|
@torreytsui I'm currently working on a similar PR: #2428. After discussing with the core-team, we rejected the PUT to only keep the POST & DELETE on a subresource (cf. comments in #1628, don't hesitate to ask me if you have any questions about it). Check the Behat scenarios for basic examples, like addind an existing object to a subresource collection. Also, with @soyuka we wanted to refactor the ApiSubresource annotation configuration to make it more maintainable, and centralize its configuration in the same annotation (currently, it's split in 3 parts). But to prevent a huge, endless & unreadable PR, we should split those 2 main features in several PRs. Would be awesome if you could help us on it 😃 |
|
@alanpoulain I didn't see #2428. That will be awesome to work on this feature together. I have got many questions / issues around it to discuss and I'm sure a team work will lead us to a better, more maintainable solution. @vincentchalamon It will be a awesome to work with you. Thanks for linking #1628. I agree that we should split them in different PRs. I also want to refactor the SubresourceOperationFactory to a more maintainable straightforward shape (basically, I want to make it not needing to reference the parent when it processes the subresource - so it is a generalisation). It will reduce the effort needed to implement more subresource features, also reduce bugs. I'm happy to raise a separate PR and discuss there. What do you guy think? Edit: After generalisation, adding support of PUT / POST / DELETE, changes in the SubresourceOperationFactory can be as simple as that (b39d3ab#diff-fdc8e25f68e3044cf8be883d3f3a7e23R146) Regarding to the REST discussion, I will start by writing up my thought on it in the #1628. Think it is a more appropriate place for incubating that ideas. |
|
@torreytsui Is this Pull Request usable using the current API Platform code? |
|
@malaimo2900 The PR is abandoned unfortunately and it is out of sync with the core. It can serve as a proof of concept or reference only. The features this PR tries to implement are complex and introduce many impacts. In my opinion, it will need a wider discussion with the core team members. |
|
Subresources have been deprecated in 2.7 and removed in 3.0 in favor of new ApiResource metadata |
TODO
@ApiSubresourceis confirmed)PATCHPATCH@ApiResource(subresourceOperations={"get"})\ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer::normalize(e.g.,
$subresource(s)_$method_subresource)try-catchworkaround (which was for keeping git history only)Subresource operations
There are two kinds of subresource operations, namely, collection operations and item operations. They are enabled slightly differently and according to if the the subresource is a collection or not, there is a different path setup as well as identifier setup.
Given an example where a property
baris a subresource of classFoo, the corresponding setup is populated as below.If
baris a collection (i.e., multiple occurrences), below operations are available:barbarbarIf
baris NOT a collection (i.e., single occurrence), below operations are available:Inheriting subresource overriding
Previously, only
get_subresourceanditem_get_subresourcewere supported and therefore, it was clear when it comes to inheriting overriding. (Only path overriding is supported for now.)Now, we in addition, support
post_subresouce,item_delete_subresource, anditem_put_subresource. This leads to two questions, when a subresource's path is overridden, (1) should the child subresource inherit from it? and (2) if we do, which subresource operation should the child inherit from?(1) As we have been offering path overridden inheritance, to keep BC, I believe we should keep supporting it.
(2) To account for the inheritance unambiguity, a simple solution can be offering inheritance fallbacks (we can't simply stick with single method (e.g., GET) because we don't know what operations will be offered by the parent subresource), giving predefined weight / priority to the subresource operation and fallback from one to others, as below:
Continue with the above foo-bar example, given that the
Barclass has abazsubresource, if the path ofbarsubresource is overridden inFooclass, what paths shouldbazsubresource be and in what operations?For collection operations, it is inheriting subresource overriding in below order, from top to bottom (if defined):
As
GEToperation is defined, the overridden path/foo/{id}/get-barsis inherited by the child subresource and thebazsubresouce have these subresource collection operation paths.For item operations, it is inheriting subresource overriding in below order, from top to bottom (if defined):
As
GEToperation is defined, the overridden path/foo/{id}/get-bars/{bar}is inherited by the child subresource and thebazsubresouce have these subresource item operation paths.Above example assumed that both
barandbazare collection. In a situation where a subresource is not a collection, the same fallback priority apply (from GET, PUT, to DELETE).Expected default behaviours
Currently, classes defined with
@ApiSubresourcewill be automatically enabled withGETmethod.In this PR,
POST,PUT,DELETE, andPATCHare offered to subresource. This leads to a question, for classes defined with@ApiSubresource, what methods should be enabled by default?https://api-platform.com/docs/core/operations/#operations
To be in line with
@ApiResource, which enablesGET(and if is collection alsoPOST),PUTandDELETE(and if is using JSON API alsoPATCH),@ApiSubresourcemakes sense to follow this behaviour. However if we go for this, it can potentially break projects which are using subresource at the moment, being unaware of the new operations offered and exposed unwanted operations to public.What do you think is the best way to handle this?
At this moment, as a proof of concept,I have followed the default behaviours of
@ApiResource.