Skip to content

(de)normalization_context is not used for subresourceOperations #1616

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

Closed
lyrixx opened this issue Dec 28, 2017 · 6 comments
Closed

(de)normalization_context is not used for subresourceOperations #1616

lyrixx opened this issue Dec 28, 2017 · 6 comments

Comments

@lyrixx
Copy link
Contributor

lyrixx commented Dec 28, 2017

According to the example in the doc, the following snippet do not work:

/**
 * @ORM\Entity()
 * @ApiResource(
 *      subresourceOperations={
 *          "answer_get_subresource"= {
 *              "method"="GET",
 *              "path"="/questions/{id}/all-answers",
 *              "normalization_context"={"groups"={"answer_read"}},
 *          },
 *      },
 * )
 */
class Question

Reprocuder: https://github.com/lyrixx/test/tree/api-platform-subresource-path

@soyuka
Copy link
Member

soyuka commented Dec 28, 2017

Mhh, I think that it's taking the "normalization_context" of the required resource class, not the class where the actual subresource is declared. I'll comment in the PR.

When I implemented subresources at first, there was no SubresourceOperation (it was a CollectionOperation).

Btw there is no "denormalization" on subresources yet.

@lyrixx
Copy link
Contributor Author

lyrixx commented Dec 28, 2017

Mhh, I think that it's taking the "normalization_context" of the required resource class, not the class where the actual subresource is declared. I'll comment in the PR.

Yes, I noticed that. But there are no way to that in a clean way. If I add a new collectionOperationType, It adds a new route :/ IMHO, this way is much more easier and intuitive.

@alifs-dev
Copy link

Hi,
The route (/questions/{id}/all-answers) appear in the answer swagger ui too. How to hide it ?
Thanks

@lyrixx
Copy link
Contributor Author

lyrixx commented Jan 19, 2018

I opened a pr for that too :-D

@Nek-
Copy link
Contributor

Nek- commented Mar 27, 2018

This is not exacly the same issue but is very close. I tried to use allow_extra_attributes context option and this doesn't work. Only the documentation example works for the context options (which is "groups").

/**
 * @ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
 * @ApiResource(
 *     attributes={"denormalization_context"={"allow_extra_attributes"=false}}
 *     collectionOperations={
 *          "get",
 *          "post"={"denormalization_context"={"groups"={"post"}}}
 *     },
 *     itemOperations={
 *          "get",
 *          "put"={"denormalization_context"={"groups"={"put"}, "allow_extra_attributes"=false}}
 *     }
 * )
 */
class Article {}

The fun part is the group I specified on "PUT" is ok, but the "allow_extra_attributes" context key is ignored.

@soyuka
Copy link
Member

soyuka commented Apr 7, 2019

Closing in favor of #2706

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants