core icon indicating copy to clipboard operation
core copied to clipboard

[Laravel] Missing Get() operation in Swagger UI with explicit REST actions

Open christophe-44-27 opened this issue 1 year ago • 1 comments

API Platform version(s) affected: 4.0.4

Description
When I use the explicit declaration of the REST action for my model, the 'Get' action (api/categories/{id}) doesn't appear in the Swagger UI or in the route list when I run 'php artisan route:list'.

Also, as you can see in the screenshots, the description of the call is 'Retrieves a Category resource' instead of 'Retrieves a Collection of Category resources'.

Note : The only model that work normaly is "User", i don't know why.

How to reproduce

  • Create a new project with Laravel 11
  • Add API Platform
  • Create a model and explicitly add the REST actions as follows:
#[ApiResource(
    operations: [
        new GetCollection(),
        new Get()
    ]
)]
  • Go to your API documentation. You'll notice that only GetCollection() is visible, while Get() is missing.

Possible Solution

Additional Context
image image

christophe-44-27 avatar Dec 12 '24 03:12 christophe-44-27

After further investigation, this is not actually a bug, but rather appears to be a documentation gap. If we don't have a database table associated with the model, API Platform does not recognize it as a valid model.

The model description in the schema is not available. Therefore, migrations need to be run first.

christophe-44-27 avatar Dec 12 '24 04:12 christophe-44-27