-
-
Notifications
You must be signed in to change notification settings - Fork 940
Add NotExposed operation #4881
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
Add NotExposed operation #4881
Conversation
4cfc2d9 to
67c835a
Compare
src/Metadata/Resource/Factory/NotFoundOperationResourceMetadataCollectionFactory.php
Outdated
Show resolved
Hide resolved
1b98423 to
803b778
Compare
8a7d622 to
1083fe9
Compare
1083fe9 to
36d4d89
Compare
f754cb8 to
9e864ae
Compare
d5cb364 to
d332726
Compare
d332726 to
bdcf7fd
Compare
soyuka
left a comment
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.
Thanks nice work!
src/Metadata/Resource/Factory/NotExposedOperationResourceMetadataCollectionFactory.php
Outdated
Show resolved
Hide resolved
src/Metadata/Resource/Factory/NotExposedOperationResourceMetadataCollectionFactory.php
Outdated
Show resolved
Hide resolved
dbadc07 to
d568390
Compare
The route name is very Symfony specific, let's use `uriTemplate` instead. The skolem id generation was moved to the IriConverter and will be in another class in a later commit.
d568390 to
ca771ce
Compare
Note that we still put this inside the Symfony class as we use the router for the url GenerationStrategy feature which is for now tight to the Symfony router
ca771ce to
39ad894
Compare
src/Metadata/Resource/Factory/NotExposedOperationResourceMetadataCollectionFactory.php
Outdated
Show resolved
Hide resolved
|
|
||
| if (!isset($context['iri']) || false !== $context['iri']) { | ||
| $jsonLdContext['@id'] = $context['iri'] ?? $this->generateSkolemIri($object); | ||
| // Not using an IriConverter here is deprecated in 2.7, avoid spl_object_hash as it may collide |
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.
Maybe add a todo here to help clear this code in 3.0
| return $this->operationCache[$operationName] = $operation; | ||
| } | ||
|
|
||
| if ($operation->getUriTemplate() === $operationName) { |
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.
| if ($operation->getUriTemplate() === $operationName) { | |
| if ($operationName === $operation->getUriTemplate()) { |
Also, the other if instances in this loop don't respect the Yoda Style.
1. Generating a default NotExposed operation to generate the IRI if the resource has no Get operation available
Description
The following resource:
When I call
GET /users, I get the following error:That's because API Platform cannot find any Get operation to generate the IRI for each collection member. A trick currently used is to manually add a Get operation with
read: false, output: false, controller: NotFoundAction::class, which is not ideal.Solution
Detect that this resource has no Get operation, and automatically add a NotExposed operation. This operation could be used to generate an IRI like
/users/{id}is the resource has an identifier, or a Skolem IRI/.well-known/genid/{id}if the resource doesn't have any identifier.TODO
2. Disabling operation from OpenApi documentation
Description
The following resource:
For any reason, I want an operation to not be exposed on the OpenApi documentation. It also implies the NotExposed auto-generated operation explained on the previous use case.
Even if it is available in the Symfony routing, it should not be available on the OpenApi documentation.
Solution
Add a
openapiboolean option on Operation to disable this operation from the OpenApi documentation.TODO
openapiboolean option on operation classesopenapiis strictly falseopenapinew operation option3. Specifying the operation to use to generate the IRI
Description
The following resource:
When I call
GET /companies/{companyId}/users, the members IRI will be the first Get operation found, so/users/{id}. But it should be/companies/{companyId}/users/{id}to be consistent with the operation initially called.Solution
Add a
itemUriTemplatestring option on Operation to specify which operation to use to generate the IRI. If this option is not set, then the default behavior is applied (select the first Get operation detected).This option is only useful for collection operations (GetCollection and Post).
TODO
itemUriTemplateoption on operation, and use it on$this->resourceMetadataCollectionFactory->getOperation()calls if available and from a collection operation contextitemUriTemplateoption4. Handling output on a resource with a GetCollection operation but with no Get operation available
Description
The following resource:
When I call
GET /userson a GetCollection with output, API Platform is trying to find a Get operation available on the output resource to generate the IRI, but it is not a resource. The following error occurs:Solution
The best solution would be to support ApiResource and ApiProperty on DTO, but it could be done in another PR. Meanwhile, it's better to return a Skolem IRI.
TODO
5. Miscellaneous