<script>
window.onload = function() {

    {% if config.JWT_AUTH_URL_RULE -%}
    // JWT token holder
    var jwt_token;
    {%- endif %}

    // Build a system
    const ui = SwaggerUIBundle(
    Object.assign(
    {

    url: "{{ specs[0]['url'] }}",
    dom_id: '#swagger-ui',
    validatorUrl: null,
    deepLinking: true,
    jsonEditor: true,
    {% if flasgger_config.doc_expansion -%}
        docExpansion: "{{flasgger_config.doc_expansion | safe }}",
    {%- endif %}
    apisSorter: "alpha",
    presets: [
        SwaggerUIBundle.presets.apis,
        SwaggerUIStandalonePreset
    ],
    plugins: [
        SwaggerUIBundle.plugins.DownloadUrl
    ],
    {% if config.JWT_AUTH_URL_RULE -%}
    requestInterceptor: function(request) {
        if (jwt_token) {
        request.headers.Authorization = "Bearer " + jwt_token;
        }

        return request;
    },
    responseInterceptor: function(response) {
        var tokenField = 'jwt-token';
        var headers = response.headers;

        if (headers.hasOwnProperty(tokenField)) {
        jwt_token = headers[tokenField];
        }

        return response;
    },
    {%- endif %}
    {% if not flasgger_config.hide_top_bar -%}
    layout: "StandaloneLayout",
    {%- endif %}
    
    },
    {{ json.dumps(flasgger_config.get('ui_params', {})) | safe }}
    {% if flasgger_config.ui_params_text -%}
    , {{ flasgger_config.ui_params_text | safe }}
    {%- endif %}
    )
    
    )

    window.ui = ui

    {% if not flasgger_config.hide_top_bar -%}
    $(".topbar-wrapper .link span").replaceWith("<span>{{title}}</span>");
    {%- endif %}
}
</script>
