Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The operation "api_users_notifications_get_subresource" cannot be found in the Swagger specification. #3973

Closed
stephanvierkant opened this issue Jan 22, 2021 · 10 comments
Assignees
Labels
Milestone

Comments

@stephanvierkant
Copy link
Contributor

stephanvierkant commented Jan 22, 2021

API Platform version(s) affected: 2.6.0. Symfony 5.2.1.

Description

curl -X GET "https://localhost:8000/api/users/20/notifications.json?page=1&itemsPerPage=10"
curl -X GET "https://localhost:8000/api/users/20/notifications?page=1&itemsPerPage=10" -H "accept: application/ld+json"
curl -X GET "https://localhost:8000/api/users/20/notifications?page=1&itemsPerPage=10" -H "accept: text/html"

This is what I found in my logs:

Uncaught PHP Exception ApiPlatform\Core\Exception\RuntimeException: "The operation "api_users_notifications_get_subresource" cannot be found in the Swagger specification." at vendor/api-platform/core/src/Bridge/Symfony/Bundle/SwaggerUi/SwaggerUiAction.php line 122 class="Symfony\Component\HttpKernel\EventListener\ErrorListener" file="vendor/symfony/http-kernel/EventListener/ErrorListener.php" function="logException" line=131 memory_peak_usage="54 MB" memory_usage="54 MB"

Uncaught PHP Exception BadMethodCallException: "Cannot serialize Symfony\Component\Cache\Adapter\AbstractAdapter" at vendor/symfony/cache/Traits/AbstractAdapterTrait.php line 322 class="Symfony\Component\HttpKernel\EventListener\ErrorListener" file="vendor/symfony/http-kernel/EventListener/ErrorListener.php" function="logException" line=131

Additional Context

$ bin/console debug:router api_users_notifications_get_subresource
+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Property     | Value                                                                                                                                                                                                                                                |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Route Name   | api_users_notifications_get_subresource                                                                                                                                                                                                              |
| Path         | /api/users/{id}/notifications.{_format}                                                                                                                                                                                                              |
| Path Regex   | {^/api/users/(?P<id>[^/]++)/notifications(?:\.(?P<_format>[^/]++))?$}sDu                                                                                                                                                                             |
| Host         | ANY                                                                                                                                                                                                                                                  |
| Host Regex   |                                                                                                                                                                                                                                                      |
| Scheme       | ANY                                                                                                                                                                                                                                                  |
| Method       | GET                                                                                                                                                                                                                                                  |
| Requirements | NO CUSTOM                                                                                                                                                                                                                                            |
| Class        | Symfony\Component\Routing\Route                                                                                                                                                                                                                      |
| Defaults     | _api_has_composite_identifier: false                                                                                                                                                                                                                 |
|              | _api_identifiers: array ('id' => array (0 => 'App\\Entity\\User\\User',1 => 'id',2 => true,),)                                                                                                                                                 |
|              | _api_resource_class: App\Entity\User\Notification                                                                                                                                                                                              |
|              | _api_subresource_context: array ('property' => 'notifications','identifiers' => array ('id' => array (0 => 'App\\Entity\\User\\User',1 => 'id',2 => true,),),'collection' => true,'operationId' => 'api_users_notifications_get_subresource',) |
|              | _api_subresource_operation_name: api_users_notifications_get_subresource                                                                                                                                                                             |
|              | _controller: api_platform.action.get_subresource()                                                                                                                                                                                                   |
|              | _format: NULL                                                                                                                                                                                                                                        |
|              | _stateless: NULL                                                                                                                                                                                                                                     |
| Options      | compiler_class: Symfony\Component\Routing\RouteCompiler                                                                                                                                                                                              |
|              | utf8: true                                                                                                                                                                                                                                           |
+--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

@jmontoyaa
Copy link
Contributor

jmontoyaa commented Jan 29, 2021

I have a probably related error, I was calling a subresource in a URL:

api/users/1/courses.json

and it was working well, after the upgrade to 2.6 there's this message in the json response:

<!-- Failed to start the session because headers have already been sent by

After some debugging If found the Symfony\Component\Cache\Adapter\AbstractAdapter error:

{"type":"https:\/\/tools.ietf.org\/html\/rfc2616#section-10","title":"An error occurred","detail":"Cannot serialize Symfony\\Component\\Cache\\Adapter\\AbstractAdapter","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"folder\/vendor\/symfony\/cache\/Traits\/AbstractAdapterTrait.php","line":322,"args":[]},{"namespace":"Symfony\\Component\\Cache\\Adapter","short_class":"AbstractAdapter","class":"Symfony\\Component\\Cache\\Adapter\\AbstractAdapter","type":"-\u003E","function":"__sleep","file":null,"line":null,"args":[]},{"namespace":"","short_class":"","class":"","type":"","function":"serialize","file":"folder\/vendor\/symfony\/http-kernel\/Profiler\/FileProfilerStorage.php","line":175,"args":[]},{"namespace":"Symfony\\Component\\HttpKernel\\Profiler","short_class":"FileProfilerStorage","class":"Symfony\\Component\\HttpKernel\\Profiler\\FileProfilerStorage","type":"-\u003E","function":"write","file":"folder\/vendor\/symfony\/http-kernel\/Profiler\/Profiler.php","line":101,"args":[]},{"namespace":"Symfony\\Component\\HttpKernel\\Profiler","short_class":"Profiler","class":"Symfony\\Component\\HttpKernel\\Profiler\\Profiler","type":"-\u003E","function":"saveProfile","file":"folder\/vendor\/symfony\/http-kernel\/EventListener\/ProfilerListener.php","line":112,"args":[]},{"namespace":"Symfony\\Component\\HttpKernel\\EventListener","short_class":"ProfilerListener","class":"Symfony\\Component\\HttpKernel\\EventListener\\ProfilerListener","type":"-\u003E","function":"onKernelTerminate","file":"folder\/vendor\/symfony\/event-dispatcher\/Debug\/WrappedListener.php","line":117,"args":[]},{"namespace":"Symfony\\Component\\EventDispatcher\\Debug","short_class":"WrappedListener","class":"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener","type":"-\u003E","function":"__invoke","file":"folder\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php","line":230,"args":[]},{"namespace":"Symfony\\Component\\EventDispatcher","short_class":"EventDispatcher","class":"Symfony\\Component\\EventDispatcher\\EventDispatcher","type":"-\u003E","function":"callListeners","file":"folder\/vendor\/symfony\/event-dispatcher\/EventDispatcher.php","line":59,"args":[]},{"namespace":"Symfony\\Component\\EventDispatcher","short_class":"EventDispatcher","class":"Symfony\\Component\\EventDispatcher\\EventDispatcher","type":"-\u003E","function":"dispatch","file":"folder\/vendor\/symfony\/event-dispatcher\/Debug\/TraceableEventDispatcher.php","line":151,"args":[]},
With api platform 2.5 works ok, but after the upgrade to 2.6 I have that error.

I think something change in the exception listener in api platform.

@stephanvierkant
Copy link
Contributor Author

I've found this in my paths (from \ApiPlatform\Core\Bridge\Symfony\Bundle\SwaggerUi\SwaggerUiAction::getPathAndMethod):

  "/api/users/{id}/notifications" => array:2 [▼
    "get" => array:7 [▼
      "operationId" => "api_users_notifications_get_subresourceUserSubresource"
      "tags" => array:2 [ …2]
      "responses" => array:1 [ …1]
      "summary" => "Retrieves a User resource."
      "description" => "Retrieves a User resource."
      "parameters" => array:24 [ …24]
      "deprecated" => false
    ]
    "parameters" => []
  ]

I don't understand why UserSubresource is appended to the operationId.

@jmontoyaa
Copy link
Contributor

Yes, I confirm I have the same issue, the string UserSubresource appears in operationId

@soyuka soyuka self-assigned this Feb 5, 2021
@soyuka soyuka added the bug label Feb 5, 2021
@stephanvierkant
Copy link
Contributor Author

https://github.com/api-platform/core/blob/v2.6.1/src/OpenApi/Factory/OpenApiFactory.php#L150

A subresource operation has no openapi_context.

@soyuka soyuka added this to the 2.6.3 milestone Feb 6, 2021
@jmontoyaa
Copy link
Contributor

This must be related with #4004

@stephanvierkant
Copy link
Contributor Author

I can confirm it is fixed in #4004. Thanks @yoshz!

@jmontoyaa
Copy link
Contributor

Fixed here too! Thanks api team!

@mbrodala
Copy link
Contributor

mbrodala commented Apr 11, 2022

Can someone add more details how exactly this is or can be fixed?

I still see this with APIP v2.6.8 as soon as there is no format in the URL and an Accept header without any supported format.

@ahmed-bhs
Copy link
Contributor

@mbrodala does there a hack to make this work on 2.6.8 ?

@mbrodala
Copy link
Contributor

Not sure but AFAIR it wasn't that much of an issue for us in the end. At least I can barely remember it. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants