/greetings route in a freshly scaffolded application produces 404 error · Issue #3003 · api-platform/api-platform · GitHub
Skip to content

/greetings route in a freshly scaffolded application produces 404 error #3003

Closed

Description

@eg-goeppert

API Platform version(s) affected: Installer 10.0.4

Description
The example resource Greetings is behaving strangely. Only one route /greetings is generated for this resource and accessing it results in the below 404 error. The provide function is never called.

{
  "@context": "/contexts/Error",
  "@id": "/errors/404",
  "@type": "Error",
  "title": "An error occurred",
  "detail": "Not Found",
  "status": 404,
  "type": "/errors/404",
  "description": "Not Found",
  "trace": [
    {
      "file": "/app/vendor/api-platform/symfony/Bundle/SwaggerUi/SwaggerUiProvider.php",
      "line": 50,
      "function": "provide",
      "class": "ApiPlatform\\State\\Provider\\ReadProvider",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/api-platform/state/Provider/DeserializeProvider.php",
      "line": 60,
      "function": "provide",
      "class": "ApiPlatform\\Symfony\\Bundle\\SwaggerUi\\SwaggerUiProvider",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/api-platform/symfony/Validator/State/ValidateProvider.php",
      "line": 32,
      "function": "provide",
      "class": "ApiPlatform\\State\\Provider\\DeserializeProvider",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/api-platform/symfony/Validator/State/ParameterValidatorProvider.php",
      "line": 102,
      "function": "provide",
      "class": "ApiPlatform\\Symfony\\Validator\\State\\ValidateProvider",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/api-platform/state/Provider/ParameterProvider.php",
      "line": 102,
      "function": "provide",
      "class": "ApiPlatform\\Symfony\\Validator\\State\\ParameterValidatorProvider",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/api-platform/state/Provider/ContentNegotiationProvider.php",
      "line": 56,
      "function": "provide",
      "class": "ApiPlatform\\State\\Provider\\ParameterProvider",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/api-platform/symfony/Controller/MainController.php",
      "line": 94,
      "function": "provide",
      "class": "ApiPlatform\\State\\Provider\\ContentNegotiationProvider",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 188,
      "function": "__invoke",
      "class": "ApiPlatform\\Symfony\\Controller\\MainController",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/symfony/http-kernel/HttpKernel.php",
      "line": 79,
      "function": "handleRaw",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/symfony/http-kernel/Kernel.php",
      "line": 143,
      "function": "handle",
      "class": "Symfony\\Component\\HttpKernel\\HttpKernel",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/symfony/runtime/Runner/FrankenPhpWorkerRunner.php",
      "line": 62,
      "function": "handle",
      "class": "Symfony\\Component\\HttpKernel\\Kernel",
      "type": "-\u003E"
    },
    {
      "function": "{closure:Symfony\\Component\\Runtime\\Runner\\FrankenPhpWorkerRunner::run():51}",
      "class": "Symfony\\Component\\Runtime\\Runner\\FrankenPhpWorkerRunner",
      "type": "-\u003E"
    },
    {
      "file": "/app/vendor/symfony/runtime/Runner/FrankenPhpWorkerRunner.php",
      "line": 72,
      "function": "frankenphp_handle_request"
    },
    {
      "file": "/app/vendor/autoload_runtime.php",
      "line": 32,
      "function": "run",
      "class": "Symfony\\Component\\Runtime\\Runner\\FrankenPhpWorkerRunner",
      "type": "-\u003E"
    },
    {
      "file": "/app/public/index.php",
      "line": 5,
      "function": "require_once"
    }
  ]
}

How to reproduce
Create a new project with the installer. I used the command from the "Getting started with symfony" example.

api-platform bookshop-api --framework=symfony --with-docker --with-pwa --with-admin

When prompted use jsonld as format and swagger for the UI. These options shouldn't really matter.
Then run the container cd bookshop-api/api && docker compose up --wait and go to http://localhost/greetings.jsonld

Additional Context
The Greetings class defines two operations Get and GetCollection but only specifies a provider for the GetCollection operation. Since there is no URI-variable defined in the Get operation, it generates the same route /greetings as the GetCollection operation.

I think this example should either omit the Get operation or add a uriTemplate: '/greeting' for this operation so it produces a separate API route. Although this would still create a route that only generates a 404 error.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions