-
-
Notifications
You must be signed in to change notification settings - Fork 893
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
[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
@ApiSubresource
is confirmed)PATCHPATCH@ApiResource(subresourceOperations={"get"})
\ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer::normalize
(e.g.,
$subresource(s)_$method_subresource
)try-catch
workaround (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
bar
is a subresource of classFoo
, the corresponding setup is populated as below.If
bar
is a collection (i.e., multiple occurrences), below operations are available:bar
bar
bar
If
bar
is NOT a collection (i.e., single occurrence), below operations are available:Inheriting subresource overriding
Previously, only
get_subresource
anditem_get_subresource
were 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
Bar
class has abaz
subresource, if the path ofbar
subresource is overridden inFoo
class, what paths shouldbaz
subresource be and in what operations?For collection operations, it is inheriting subresource overriding in below order, from top to bottom (if defined):
As
GET
operation is defined, the overridden path/foo/{id}/get-bars
is inherited by the child subresource and thebaz
subresouce have these subresource collection operation paths.For item operations, it is inheriting subresource overriding in below order, from top to bottom (if defined):
As
GET
operation is defined, the overridden path/foo/{id}/get-bars/{bar}
is inherited by the child subresource and thebaz
subresouce have these subresource item operation paths.Above example assumed that both
bar
andbaz
are 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
@ApiSubresource
will be automatically enabled withGET
method.In this PR,
POST
,PUT
,DELETE
, andPATCH
are 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
),PUT
andDELETE
(and if is using JSON API alsoPATCH
),@ApiSubresource
makes 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
.