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

No item route associated when itemOperations is set but empty #3501

Closed
symfonyaml opened this issue Apr 17, 2020 · 4 comments
Closed

No item route associated when itemOperations is set but empty #3501

symfonyaml opened this issue Apr 17, 2020 · 4 comments

Comments

@symfonyaml
Copy link

API Platform version(s) affected: 2.5.4

Description

When the itemOperations is empty, and collectionOperations is set, there is an error when fetching the collection like [GET] /api/books

No item route associated with the type "App\Entity\Book"
error in RouteNameResolver.php line 62

How to reproduce

Create an entity with the api mapping

App\Entity\Book:
    itemOperations: {} # <---- this creates the bug
    collectionOperations: { get: ~ }

Possible Solution

in RouteNameResolver.php line 50, the value returned in the sprintf for $operationType should be collection, but its item instead.

Then the route default value _api_item_operation_name does not exists so no route is not found.
When I replace by _api_collection_operation_name it works.

Occurences

@soyuka
Copy link
Member

soyuka commented Apr 18, 2020

Indeed the safe way to diable item operations is to do:

/**
 * @ApiResource(
 *     itemOperations={
 *         "get"={
 *             "method"="GET",
 *             "controller"=NotFoundAction::class,
 *             "read"=false,
 *             "output"=false,
 *         },
 *     },
 * )
 */

As documented at the end of this section.

@symfonyaml
Copy link
Author

symfonyaml commented Apr 18, 2020

@soyuka thanks for your answer.
Unfortunately your solution still list the get item endpoint in the swagger doc.
I am really confused why it would not be possible to just have a list endpoint for an entity.

@versh23
Copy link

versh23 commented Apr 20, 2020

you can remove it by swagger decorator https://api-platform.com/docs/core/swagger/#overriding-the-openapi-specification

@akerouanton
Copy link

You can also manually set the IRI used by the normalization context, such that it won't try to generate one:

App\Entity\Book:
    itemOperations: {}
    collectionOperations: { get: { normalization_context: { iri: "" } } }

@soyuka soyuka closed this as completed Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants