I'm trying to do pretty much what is explained in https://api-platform.com/docs/core/operations/#expose-a-model-without-any-routes. To stick to that example, I have:
- An API resource
Placewith full CRUD functionality - Another model
Weatherthat represents the weather of a place and I want to have aGET /places/{id}/weatherendpoint to get the weather of a specific place.
The solutions that I came up with and the problems I see in them
- Having an API Platform independent controller/route that handles this
- The route is not showing up in the OpenAPI documentation (could implement this myself of course)
- I don't benefit from the built-in serialization features and have to implement this myself
- Making
Weathera resource and creating it via custom Controller as done in https://api-platform.com/docs/core/operations/#expose-a-model-without-any-routesWeatherneeds an ID to work (right?)- Referencing a non-existant Controller and removing endpoints from the OpenAPI documentation but NOT their routes feels very hacky to me
- Making
Weathera subresource- A
weatherproperty/reference in myPlaceresource is incorrect / not needed Weatherneeds an ID again which is not wanted
- A
- Making
Weathera dedicated API resource and using a custom Controller or DataProvider with the places ID- I'm kind of misusing the
PlaceID forWeather
- I'm kind of misusing the
- Making
Weathera custom representation / output / DTO ofPlacewith a custom route and a custom ControllerWeatheris not aPlace
I currently went with the last solution because I could get rid of the ID in Weather and only needed a text adaption in the OpenAPI documentation. The annotation that I'm using in Place is looking like the following
* @ApiResource(
* itemOperations={
* "get",
* "delete",
* "put",
* "patch",
* "get_weather"={
* "method"="GET",
* "path"="/places/{id}/weather",
* "controller"=WeatherController::class,
* "output"=Weather::class
* }
* },
* )
But there must be a better solution for this, right? Am I overlooking something?