-
-
Notifications
You must be signed in to change notification settings - Fork 874
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
Drop Twig Dependency #1149
Comments
I believe we can drop Twig entirely even when using the Swagger UI by ensuring that it's fully client-side. |
In fact I think separating "Swagger UI for Symfony" project can be more reasonable. |
Yes, I see no reason for this project to include any JS and CSS, etc. It should live in a separate frontend project, like https://github.com/api-platform/admin and https://github.com/api-platform/generate-crud. It should be included as part of our Docker Compose setup. And with Symfony Flex it should be pretty easy to advise the user to install it separately (or even auto-install?). |
@api-platform/core-team One guiding principle for web APIs is the separation of the frontend and the backend. I believe we need to set a good example ourselves. |
I definitely agree with that, but it's easiest solution right now. We can work to do it in 2.2! |
What if we use EasyAdminBundle or another bundle which requires Twig ? |
@pierre-H this doesn't mean that you can't have twig as a dependency in your project :). This is just a proposal to drop the |
There is no hard dependency on Twig in core. It's just a soft dep. |
Actually the Symfony bridge's service "api_platform.swagger.action.ui" introduce a hard dependency with Twig (still true is the 2.2-beta). |
@fgrandjean Do you have some time to implement this ? |
@Simperfit I can, but i do need some direction : Do we go for a clearer exception that tell end user that when used with Symfony they are required to add twig as a deps or do we silently toggle on/off the Swagger ui based on deps (as the Sf FrameworkBundle does) ? |
@fgrandjean I think we need to toggle silently off when twig is not part of the project. WDYT @api-platform/core-team ? |
|
Taking a closer look it seems swagger-ui is not the only hard dependency on twig. "api_platform.graphql.action.entrypoint" also introduce a hard dependency. |
It's the same for graphiql it's ui should be loaded separatly |
We should replace Twig by the Symfony Templating component and its PHP templating engine! 😋 |
Twig dependency is dev-only now so I guess this can be closed. |
looks like it's not closed... 😭 Symfony version: 5.1.3 Here's what I get
I can help making the PR next week if somebody can guide me a bit about what to do. |
I guess that about swagger ui action we can somehow conditionnaly load the swagger-ui.xml file. But then... if I comment it to test I'm facing the same issue but this time with graphiql.
I've not find at the moment where I could fix this one, can anybody help me? |
I finally wiped out the errors but this is a lot of things to conditionnally load depending if twig is installed or not. Especially at the moment looks like it's not easy when graphql is enabled to not install twig as a production requirement. |
So... should I throw exceptions when twig is not available but graphql enabled or swagger ui enabled? 🤔 |
Ok, so I've found this PR that has never been merged and that looks like a good starting point: #1829 |
@dunglas @teohhanhui I've found a fix by overriding swagger ui action service in my own application: services:
# this service is not lazy and requires twig so let's override it
api_platform.swagger.action.ui:
class: ApiPlatform\Core\Bridge\Symfony\Bundle\Action\SwaggerUiAction So... if you want I can make a PR but I see at least 2 to do things:
Which one do you prefer? (Alternatives accepted). |
I think this library mostly aims API first or API only projects. Twig is an unnecessary dependency with
enable_swagger_ui: false
but still needed forapi_platform.swagger.action.ui
service.The text was updated successfully, but these errors were encountered: