From cbab00939f07ce6f5e64823d72e33de43aa0427f Mon Sep 17 00:00:00 2001 From: Baptiste Lafontaine Date: Fri, 23 Oct 2020 15:04:00 +0200 Subject: [PATCH] Allow to pass options to the constructor of SwaggerUIBundle --- Resources/public/init-swagger-ui.js | 8 +++++--- Resources/views/SwaggerUi/index.html.twig | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Resources/public/init-swagger-ui.js b/Resources/public/init-swagger-ui.js index 892a2b6..8fad535 100644 --- a/Resources/public/init-swagger-ui.js +++ b/Resources/public/init-swagger-ui.js @@ -5,9 +5,9 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -window.onload = function() { +function loadSwaggerUI(userOptions = {}) { const data = JSON.parse(document.getElementById('swagger-data').innerText); - const ui = SwaggerUIBundle({ + const defaultOptions = { spec: data.spec, dom_id: '#swagger-ui', validatorUrl: null, @@ -19,7 +19,9 @@ window.onload = function() { SwaggerUIBundle.plugins.DownloadUrl ], layout: 'StandaloneLayout' - }); + }; + const options = Object.assign({}, defaultOptions, userOptions); + const ui = SwaggerUIBundle(options); const storageKey = 'nelmio_api_auth'; diff --git a/Resources/views/SwaggerUi/index.html.twig b/Resources/views/SwaggerUi/index.html.twig index ec7efa6..82e1332 100644 --- a/Resources/views/SwaggerUi/index.html.twig +++ b/Resources/views/SwaggerUi/index.html.twig @@ -66,8 +66,11 @@ file that was distributed with this source code. #} {% endblock javascripts %} + {% block swagger_initialization %} - + {% endblock swagger_initialization %}