Allow to pass options to the constructor of SwaggerUIBundle

This commit is contained in:
Baptiste Lafontaine 2020-10-23 15:04:00 +02:00
parent 2f8416618d
commit cbab00939f
2 changed files with 9 additions and 4 deletions

View File

@ -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';

View File

@ -66,8 +66,11 @@ file that was distributed with this source code. #}
<script src="{{ asset('bundles/nelmioapidoc/swagger-ui/swagger-ui-standalone-preset.js') }}"></script>
{% endblock javascripts %}
<script src="{{ asset('bundles/nelmioapidoc/init-swagger-ui.js') }}"></script>
{% block swagger_initialization %}
<script src="{{ asset('bundles/nelmioapidoc/init-swagger-ui.js') }}"></script>
<script type="text/javascript">
window.onload = loadSwaggerUI();
</script>
{% endblock swagger_initialization %}
</body>
</html>