Suggestion for easier way to find specific operations in ResourceMetadataCollection
API Platform version(s) affected: 3.0.0
Description
Below might be a mistake on my side, on how to properly use getOperation. Apologize if I miss an obvious point.
I notice that it's hard to find a default CRUD operation of a resource when using ResourceMetadataCollection->getOperation.
If I understood correctly, it's relatively easy to find the default (=first) Get or GetCollection:
$resourceMetadataCollection->getOperation(null, false, true) // returns the first Get
$resourceMetadataCollection->getOperation(null, true, true) // returns the first GetCollection
However, it's relatively complex to find any of the other operations. I need to know or build the complete route name for the operation:
$resourceMetadataCollection->getOperation("_api_/books/{id}.{_format}_patch") // returns the default Patch operation
Would be nice to search for a class match, e.g.
$resourceMetadataCollection->getOperationByType(Patch::class) // returns the first Patch operation
Would this make sense? Or do I miss an obvious way to achieve this already?
what if there're many Patch operations ? You should probably implement your own service for searching operations. Note that getOperation works with an uriTemplate as well IIRC.
what if there're many Patch operations ?
Yeah, in that case one would need to search via $operationName (or other specific search service). Even though multiple ApiResources are now allowed containing multiple operations of the same type, in many cases the default would probably still be to have 1 ApiResource containing the default CRUD-operations (at least it's the case for us).
Having a quick/easy way to return this default CRUD operations would be helpful, as using getOperation with $operationName===null already achieves this for the R part already.
You should probably implement your own service for searching operations.
Sure, can implement on our side. We can close this here if not of value to others.