2018-07-16 09:45:18 +02:00
Customization
=============
The look and feel of the Swagger UI can be customized.
Overwrite Twig Template
-----------------------
If you want to customize parts of the template, you can create your own Twig template.
2020-11-02 11:21:34 +01:00
This allows to change Swagger UI configuration, page title, page header, add additional or replace existing styles or scripts.
2018-07-16 09:45:18 +02:00
Take a look at the Twig documentation `how to extend templates <https://twig.symfony.com/doc/2.x/tags/extends.html> `_ .
The following example will add additional scripts and a custom style to the template.
2018-10-19 20:11:39 +02:00
Just create a file `` templates/bundles/NelmioApiDocBundle/SwaggerUi/index.html.twig `` .
2018-07-16 09:45:18 +02:00
.. code-block :: twig
2018-10-19 20:11:39 +02:00
{# templates/bundles/NelmioApiDocBundle/SwaggerUi/index.html.twig #}
2018-07-16 09:45:18 +02:00
{#
To avoid a "reached nested level" error an exclamation mark `!` has to be added
See https://symfony.com/blog/new-in-symfony-3-4-improved-the-overriding-of-templates
#}
{% extends '@!NelmioApiDoc/SwaggerUi/index.html.twig' %}
2020-11-02 11:21:34 +01:00
{#
Change swagger UI configuration
All parameters are explained on Swagger UI website:
https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
#}
{% block swagger_initialization %}
<script type="text/javascript">
window.onload = loadSwaggerUI({
defaultModelsExpandDepth: -1,
deepLinking: true,
});
</script>
{% endblock %}
{# Import your own stylesheet #}
2018-07-16 09:45:18 +02:00
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('css/custom-swagger-styles.css') }}">
{% endblock stylesheets %}
2020-11-02 11:21:34 +01:00
{# Import your own script #}
2018-07-16 09:45:18 +02:00
{% block javascripts %}
{{ parent() }}
<script type="text/javascript" src="{{ asset('js/custom-request-signer.js') }}"></script>
{% endblock javascripts %}
2021-11-03 19:13:42 -04:00
You can have a look at the `original template <https://github.com/nelmio/NelmioApiDocBundle/blob/master/Resources/views/SwaggerUi/index.html.twig> `_ , in `` /Resources/views/SwaggerUi/index.html.twig `` , to see which blocks can be overridden.