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

Wrong route match if routePrefix is defined #5203

Closed
usu opened this issue Nov 20, 2022 · 2 comments · Fixed by #5252
Closed

Wrong route match if routePrefix is defined #5203

usu opened this issue Nov 20, 2022 · 2 comments · Fixed by #5252

Comments

@usu
Copy link
Contributor

usu commented Nov 20, 2022

API Platform version(s) affected: 3.0.4

Description
As of now, routePrefix is not included in operation name (which also serves as the symfony route name). This can lead to route name conflict and hence to wrong route matches, if multiple resources are defined on the the same resource class.

How to reproduce

  1. Specify a resource class with 2 ApiResources, one of them with a routePrefix:
#[ApiResource(
    operations: [
        new Get(
            security: 'true'
        ),
        new GetCollection(
            security: 'true'
        ),
)]
#[ApiResource(
    operations: [
        new Get(
            security: 'false'
        ),
        new GetCollection(
            security: 'false'
        ),
    ],
    routePrefix: '/admin'
)]
class User {
}
  1. Load '/admin/users'

Expected result: 403 Forbidden (matching GetCollection operation of the second ApiResource)

Received result: 200 (matching GetCollection operation of first ApiResource). Confusingly, the individual IRIs are still prefixed with /admin

{
  "_links": {
    "self": {
      "href": "/admin/users"
    },
    "items": [
      {
        "href": "/admin/users/1234"
      },
      {
        "href": "/admin/users/5678"
      }
    ]
  },
  "totalItems": 2
}

Possible Solution
Include routePrefix in operation name

Additional context

  • In SwaggerUI, only the /admin/users endpoint are shown (see screenshot below)
  • The routes of the first ApiResource seems to overwritten in Symfony router. Loading /users leads to a "404 No route found exception"

SwaggerUI:
Screenshot 2022-11-20 073837

Route Match Log:
Screenshot 2022-11-20 074206

@soyuka soyuka moved this to Todo in @soyuka's todolist Nov 21, 2022
@soyuka soyuka moved this from Todo to In Progress in @soyuka's todolist Nov 21, 2022
@soyuka soyuka closed this as completed Nov 23, 2022
Repository owner moved this from In Progress to Done in @soyuka's todolist Nov 23, 2022
@usu
Copy link
Contributor Author

usu commented Dec 3, 2022

Hi @soyuka. Could this issue be reopened? Not sure if you saw my comment directly in the PR #5208 (comment), but I think this is not yet resolved.

@divine
Copy link
Contributor

divine commented Dec 18, 2022

@soyuka sorry to bump, this can be closed as PR has been merged.

Thanks!

@soyuka soyuka closed this as completed Dec 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

3 participants