Because in API Platform (and when following the web architecture in general), it's better to identify every resources using an IRI, it's what does API Platform by default. While not mandatory, it's also considered a best practice for an IRI to be "dereferencable". When requesting the IRI, a representation of the resource, or the associated documentation should be displayed.
However, sometimes, you need to use reference to resources that aren't publicly available. Because API Platform internally uses the Symfony router to map objects to URL (forth and back), a route must exist for any resource type exposed through the API (or, in PHP term, for any class marked with @ApiResource). A common problem with API Platform is that because of this the GET operation must always exist, but sometimes you don't want this route (used to generate IRIs) to return anything. In this case, also want to this route to be hidden from the OpenAPI documentation, because it is useless for humans and code generator. This kind of routes are just placeholders used to generate identifiers.
My proposal is to introduce a new operation attribute, called iriOnly. When set to true, the route will exist but will return a 404 not found status code, and no PHP code, nor SQL request will be triggered. Also, such operations will be automatically hidden from OpenAPI and Swagger documentations. Optionally, a HTTP status code could be associated with this attribute, such as iriOnly=204.
Because in API Platform (and when following the web architecture in general), it's better to identify every resources using an IRI, it's what does API Platform by default. While not mandatory, it's also considered a best practice for an IRI to be "dereferencable". When requesting the IRI, a representation of the resource, or the associated documentation should be displayed.
However, sometimes, you need to use reference to resources that aren't publicly available. Because API Platform internally uses the Symfony router to map objects to URL (forth and back), a route must exist for any resource type exposed through the API (or, in PHP term, for any class marked with
@ApiResource). A common problem with API Platform is that because of this theGEToperation must always exist, but sometimes you don't want this route (used to generate IRIs) to return anything. In this case, also want to this route to be hidden from the OpenAPI documentation, because it is useless for humans and code generator. This kind of routes are just placeholders used to generate identifiers.My proposal is to introduce a new operation attribute, called
iriOnly. When set to true, the route will exist but will return a 404 not found status code, and no PHP code, nor SQL request will be triggered. Also, such operations will be automatically hidden from OpenAPI and Swagger documentations. Optionally, a HTTP status code could be associated with this attribute, such asiriOnly=204.