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

2.7.3 ignores the route_prefix prefix settings #5179

Closed
DarkChyper opened this issue Nov 10, 2022 · 8 comments · Fixed by #5194
Closed

2.7.3 ignores the route_prefix prefix settings #5179

DarkChyper opened this issue Nov 10, 2022 · 8 comments · Fixed by #5194

Comments

@DarkChyper
Copy link

DarkChyper commented Nov 10, 2022

Hello,
I found this message in a closed issue named "Issues found on 2.7" because i reproduce this issue with 2.7.3 (SF 4.4.45 PHP 7.4)

route_prefix is still ignored when i try to migrate from 2.6 to 2.7 (cannot go to 3.x now).

I don't find any fix for this (but i'm not good to read PR, i could miss it)

edit: it works if i add setting on each resource :
config/api/resources/myresource.yaml

resources:
  My\Resource:
    routePrefix: 'v2'
    @soyuka, it seems the latest version ignores the `route_prefix` prefix settings

config/packages/api_platform.yaml

api_platform:
...
    metadata_backward_compatibility_layer: false
    openapi:
        backward_compatibility_layer: false
    defaults:
        route_prefix: '/api'

GET /users/{id} Retrieves a User resource.
Instead of
GET /api/users/{id} Retrieves a User resource.

Tested with d876e66

Originally posted by @lermontex in #4613 (comment)

@DarkChyper DarkChyper changed the title @soyuka, it seems the latest version ignores the route_prefix prefix settings 2.7. ignores the route_prefix prefix settings Nov 10, 2022
@DarkChyper DarkChyper changed the title 2.7. ignores the route_prefix prefix settings 2.7.3 ignores the route_prefix prefix settings Nov 10, 2022
@vincentchalamon
Copy link
Contributor

Hi @DarkChyper,

I've tried to reproduce your bug locally, but couldn't get the same bug as you. Can you provide a reproducer, please? You can use a fork of api-platform/api-platform 😉

Here is the configuration I've tried, tested with both API Platform 2.7.4 (Symfony 5.4.15) and 3.0.4 (Symfony 6.1.7):

# routes/api_platform.yaml
api_platform:
    resource: .
    type: api_platform
    prefix: /symfony
# config/packages/api_platform.yaml
api_platform:
    # ...
    metadata_backward_compatibility_layer: false # api-platform/core:^2.7 only
    defaults:
        route_prefix: /api
#[ApiResource(routePrefix: 'v2')]
class Greeting
#[ApiResource]
class Book

When I list the routes (using bin/console debug:router), I've got the following result, which is correct:

image

Just to be clear: the /symfony prefix is present everywhere because it is related to the Symfony routing. The api_platform.defaults.prefix defines a prefix on every API Platform resource and operation, it is not directly related to the Symfony routing, it inherits it! However, it can be overriden by resource and operation (e.g.: in Greeting and Book classes), but still inherits the Symfony routing prefix (which results to /symfony/v2/books).

@DarkChyper
Copy link
Author

DarkChyper commented Nov 16, 2022

Hi @vincentchalamon thanks for the answer !

I'll try to provide a reproducer, maybe the issue come from something with symfony 4.4.45 or yaml serializer (we don't use annotation on entities)

@vincentchalamon
Copy link
Contributor

Ah ok, it changes some things indeed. I can now reproduce the bug using the following configuration:

resources:
    App\Entity\Greeting:
        routePrefix: v2
    App\Entity\Book: ~

I only have the bug on API Platform 2.7, not on 3.0

@DarkChyper
Copy link
Author

ok so it seems that there is no bug with symfony 5.x and api platform 2.7.
Maybe i have to wait to upgrade the project to 5.x before update api platform on my project ( i have another issue with circular reference on non api resource of sub resource.. )

@vincentchalamon
Copy link
Contributor

Should be fixed in #5194. Thanks for reporting this issue

@FPDK
Copy link

FPDK commented Nov 25, 2022

@vincentchalamon Is it intentional that the ApiResource-specific routePrefix will be ignored if the ApiResource only contains graphQlOperations?

Example:

#[ApiResource(
    operations: [],
    routePrefix: '/resourceSpecificPrefix',
    graphQlOperations: [
        new Query(name: 'item_query'),
        new QueryCollection(name: 'collection_query'),
    ],
)]

If operations is [] then the ApiResource IRI is not prefixed in GraphQL queries. If the operations is [new Get(),] then the IRI is prefixed correctly in GraphQL queries.

@vincentchalamon
Copy link
Contributor

Hello @FPDK,
Can you please open a new issue describing this issue, ideally with a reproducer, please?

@soyuka
Copy link
Member

soyuka commented Nov 25, 2022

there's no routes inside graphql no ?

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

Successfully merging a pull request may close this issue.

4 participants