core
core copied to clipboard
CollectionOperation GET|POST with nested path no longer working in API-Platform v3.2 (coming from v2.4)
API Platform version(s) affected: 3.2
Description
During migration from API-Platform 2.4 to 3.2 we encountered the following problem:
In version 2.4 it was possible to declare a collection endpoint with a nested path - e.g. /books/invoice
After migration to API-Platform 3.2 I get a 404 error when calling this endpoint.
Are nested paths without parameters not allowed anymore?
Declaration before migration:
/**
* API Entity "Book"
*
* @ApiResource(
* collectionOperations={
* "get"={},
* "post"={},
* "get_invoice"={
* "method"="GET",
* "path"="/books/invoice",
* "swagger_context"={
* "summary"="Gets all books that have not yet been invoiced"
* }
* }
* },
* itemOperations={
* "get"={},
* "put"={},
* "delete"={}
* }
* )
*/
Code after migration:
/**
* API Entity "Book"
*/
#[ApiResource(
operations: [
new Get(),
new Put(),
new Delete(),
new GetCollection(),
new Post(),
new GetCollection(
uriTemplate: '/books/invoice',
provider: BookInvoiceProvider::class,
openapi: new Operation(
summary: 'Gets all books that have not yet been invoiced',
)
)
]
)]
The debug:router commands shows _api/books/invoice_get_collection GET ANY ANY /api/books/invoice. But the router matches the single GET endpoint.
php bin/console router:match /api/books/invoice
[OK] Route "api/books/{id}{._format}_get" matches Changing uriTemplate to "books_invoice" would solve the issue. But I was wondering why it doesn't work anymore.
How to reproduce
Trying to access a API resources collection endpoint with configured nested path as uriTemplate in GetCollection (see above)
Additional Context
Migrating from API-Platform v2.4 -> v3.2
Already posted here: https://github.com/api-platform/api-platform/issues/2618 with no reaction yet. Unfortunately this is quite critical for us, as we want to avoid breaking changes as far as possible. Is there any chance that someone will take care of this problem? Or should we use commercial support?
Order matter when declaring operations.
@soyuka Sorry to bother you, but is/was this issue really resolved? And how? Or should I just adding requirements to the operation as suggested/proposed here https://github.com/api-platform/api-platform/issues/2618#issuecomment-1929368596? In the latter case, IMHO, there is no corresponding information in the documentation, especially because the previous behavior has changed. Or have you done any code changes (I neither can find any related commits nor is one referenced here).