Compatibility bug with Symfony 6.1 & ApiPlatform 3.0
ppoz21 opened this issue · 6 comments
Hi everyone,
I have problem with Symfony 6.1.0 and ApiPlatform 3.0.0
After installing bundle via composer all my API routes disappeared (only LexikJWT route added by OpenAPI decorator left)
When I remove bundle from bundles.php all endpoints return
Here is my code:
RefreshToken.php
<?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;
#[ORM\Entity]
#[ORM\Table('`refresh_tokens`')]
class RefreshToken extends BaseRefreshToken
{
}
security.yaml
security:
password_hashers:
Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
enable_authenticator_manager: true
providers:
app_user_provider:
entity:
class: App\Entity\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
stateless: true
provider: app_user_provider
entry_point: jwt
json_login:
check_path: /authentication_token
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
jwt: ~
refresh_jwt:
check_path: /token/refresh
provider: app_user_provider
access_control:
- { path: ^/authentication_token, roles: PUBLIC_ACCESS }
- { path: ^/token/refresh, roles: PUBLIC_ACCESS }
- { path: ^/api$, roles: PUBLIC_ACCESS }
# - { path: ^/, roles: IS_AUTHENTICATED_FULLY }
Anyone have any solution?
I got the same problem here too.
I just see that when enabling the bundle all the routes of the Entities disappear from the routes list.
With bundle enabled
-------------------------- -------- -------- ------ ------------------------------------- ---------------------------------------------------------
Name Method Scheme Host Path Controller
-------------------------- -------- -------- ------ ------------------------------------- ---------------------------------------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format} error_controller::preview()
_wdt ANY ANY ANY /_wdt/{token} web_profiler.controller.profiler::toolbarAction()
_profiler_home ANY ANY ANY /_profiler/ web_profiler.controller.profiler::homeAction()
_profiler_search ANY ANY ANY /_profiler/search web_profiler.controller.profiler::searchAction()
_profiler_search_bar ANY ANY ANY /_profiler/search_bar web_profiler.controller.profiler::searchBarAction()
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo web_profiler.controller.profiler::phpinfoAction()
_profiler_xdebug ANY ANY ANY /_profiler/xdebug web_profiler.controller.profiler::xdebugAction()
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results web_profiler.controller.profiler::searchResultsAction()
_profiler_open_file ANY ANY ANY /_profiler/open web_profiler.controller.profiler::openAction()
_profiler ANY ANY ANY /_profiler/{token} web_profiler.controller.profiler::panelAction()
_profiler_router ANY ANY ANY /_profiler/{token}/router web_profiler.controller.router::panelAction()
_profiler_exception ANY ANY ANY /_profiler/{token}/exception web_profiler.controller.exception_panel::body()
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css web_profiler.controller.exception_panel::stylesheet()
auth_user_login POST ANY ANY /authentication/user/login
auth_user_refresh ANY ANY ANY /authentication/user/refresh
api_genid ANY ANY ANY /api/.well-known/genid/{id} api_platform.action.not_exposed()
api_entrypoint ANY ANY ANY /api/{index}.{_format} api_platform.action.entrypoint()
api_doc ANY ANY ANY /api/docs.{_format} api_platform.action.documentation()
api_jsonld_context ANY ANY ANY /api/contexts/{shortName}.{_format} api_platform.jsonld.action.context()
-------------------------- -------- -------- ------ ------------------------------------- ---------------------------------------------------------
With bundle disabled:
----------------------------------------- -------- -------- ------ ------------------------------------- ---------------------------------------------------------
Name Method Scheme Host Path Controller
----------------------------------------- -------- -------- ------ ------------------------------------- ---------------------------------------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format} error_controller::preview()
_wdt ANY ANY ANY /_wdt/{token} web_profiler.controller.profiler::toolbarAction()
_profiler_home ANY ANY ANY /_profiler/ web_profiler.controller.profiler::homeAction()
_profiler_search ANY ANY ANY /_profiler/search web_profiler.controller.profiler::searchAction()
_profiler_search_bar ANY ANY ANY /_profiler/search_bar web_profiler.controller.profiler::searchBarAction()
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo web_profiler.controller.profiler::phpinfoAction()
_profiler_xdebug ANY ANY ANY /_profiler/xdebug web_profiler.controller.profiler::xdebugAction()
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results web_profiler.controller.profiler::searchResultsAction()
_profiler_open_file ANY ANY ANY /_profiler/open web_profiler.controller.profiler::openAction()
_profiler ANY ANY ANY /_profiler/{token} web_profiler.controller.profiler::panelAction()
_profiler_router ANY ANY ANY /_profiler/{token}/router web_profiler.controller.router::panelAction()
_profiler_exception ANY ANY ANY /_profiler/{token}/exception web_profiler.controller.exception_panel::body()
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css web_profiler.controller.exception_panel::stylesheet()
auth_user_login POST ANY ANY /authentication/user/login
auth_user_refresh ANY ANY ANY /authentication/user/refresh
api_genid ANY ANY ANY /api/.well-known/genid/{id} api_platform.action.not_exposed()
api_entrypoint ANY ANY ANY /api/{index}.{_format} api_platform.action.entrypoint()
api_doc ANY ANY ANY /api/docs.{_format} api_platform.action.documentation()
api_jsonld_context ANY ANY ANY /api/contexts/{shortName}.{_format} api_platform.jsonld.action.context()
_api_/students/{id}.{_format}_get GET ANY ANY /api/students/{id}.{_format} api_platform.action.placeholder()
_api_/students.{_format}_get_collection GET ANY ANY /api/students.{_format} api_platform.action.placeholder()
_api_/students.{_format}_post POST ANY ANY /api/students.{_format} api_platform.action.placeholder()
_api_/students/{id}.{_format}_put PUT ANY ANY /api/students/{id}.{_format} api_platform.action.placeholder()
_api_/students/{id}.{_format}_patch PATCH ANY ANY /api/students/{id}.{_format} api_platform.action.placeholder()
_api_/students/{id}.{_format}_delete DELETE ANY ANY /api/students/{id}.{_format} api_platform.action.placeholder()
_api_/users/{id}.{_format}_get GET ANY ANY /api/users/{id}.{_format} api_platform.action.placeholder()
_api_/users.{_format}_get_collection GET ANY ANY /api/users.{_format} api_platform.action.placeholder()
_api_/users.{_format}_post POST ANY ANY /api/users.{_format} api_platform.action.placeholder()
_api_/users/{id}.{_format}_put PUT ANY ANY /api/users/{id}.{_format} api_platform.action.placeholder()
_api_/users/{id}.{_format}_patch PATCH ANY ANY /api/users/{id}.{_format} api_platform.action.placeholder()
_api_/users/{id}.{_format}_delete DELETE ANY ANY /api/users/{id}.{_format} api_platform.action.placeholder()
----------------------------------------- -------- -------- ------ ------------------------------------- ---------------------------------------------------------
I use the same configuration that @ppoz21 is given in the example above.
EDIT: The console debug:api-resource I can debug the API resource with no problem.
Hi!
I use google translation.
I have the same problem also.
First of all the bundle disrupted the functioning of the maker-bundle. Take a look at this issue.
Then after configuration all my routes that are generated with the #[ApiResource]
attribute disappear completely.
I think the bundle is not ready for symfony 6 yet
I think the problem is that entity is using the old style annotation of doctrine instead of the PHP 8 attributes.
I think the problem is that entity is using the old style annotation of doctrine instead of the PHP 8 attributes.
The doc examples and the file added by the Flex recipe use annotations, but if your application is using attributes, you can update the code in your application to use those. Annotations use is still valid on PHP 8, but the ecosystem is moving away from it (if everything only documented/configured attributes by default, then folks running on PHP 7 would have broken apps; it's one of those "you can't win them all" situations).
Hi everyone, is there any workaround?
As described by others, API platform API resources are debug-able but they don't appear in routing therefore the routes are not callable and they don't appear in swagger. It feels like it's preventing API platform from registering routes which makes no sense to me if it's not decorated with the #[ApiResource]
I have changed my RefreshToken entity to
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;
#[ORM\Entity]
#[ORM\Table(name: 'refresh_tokens')]
class RefreshToken extends BaseRefreshToken { }
security.yml
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js|docs.jsonld|docs|nextjs)/
security: false
main:
pattern: ^/
stateless: true
lazy: true
provider: app_user_provider
entry_point: jwt
json_login:
check_path: /token/request
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
jwt: ~
refresh_jwt:
check_path: /token/refresh
access_control:
- { path: ^/(docs|docs.jsonld), roles: PUBLIC_ACCESS }
- { path: ^/token/(refresh|request), roles: PUBLIC_ACCESS }
- { path: ^/admin, roles: PUBLIC_ACCESS }
- { path: ^/form_datas/submit/*/*, roles: PUBLIC_ACCESS }
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }
routes/token.yml
token_request:
path: /token/request
methods: [ 'POST' ]
token_refresh:
path: /token/refresh
controller: gesdinet.jwtrefreshtoken::refresh
/srv/app # php bin/console debug:router
-------------------------- -------- -------- ------ -----------------------------------
Name Method Scheme Host Path
-------------------------- -------- -------- ------ -----------------------------------
api_genid ANY ANY ANY /.well-known/genid/{id}
api_entrypoint ANY ANY ANY /{index}.{_format}
api_doc ANY ANY ANY /docs.{_format}
api_jsonld_context ANY ANY ANY /contexts/{shortName}.{_format}
_preview_error ANY ANY ANY /_error/{code}.{_format}
token_request POST ANY ANY /token/request
token_refresh ANY ANY ANY /token/refresh
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_xdebug ANY ANY ANY /_profiler/xdebug
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
Don't know what made a difference, maybe installing symfony then adding api-platform, but flex + api-platform actually works.