Fix swagger-ui style when session auth is disabled

openapi3
Cristi Vîjdea 2018-09-09 21:52:02 +03:00
parent 824baf7e9d
commit ec7529399e
3 changed files with 11 additions and 10 deletions

View File

@ -19,10 +19,6 @@ body.swagger-body {
background: #fafafa;
}
#django-session-auth {
margin-right: 8px;
}
.hidden {
display: none;
}

View File

@ -6,6 +6,11 @@ function patchSwaggerUi() {
var authWrapper = document.querySelector('.auth-wrapper');
var authorizeButton = document.querySelector('.auth-wrapper .authorize');
var djangoSessionAuth = document.querySelector('#django-session-auth');
if (!djangoSessionAuth) {
console.log("WARNING: session auth disabled");
return;
}
if (document.querySelector('.auth-wrapper #django-session-auth')) {
console.log("WARNING: session auth already patched; skipping patchSwaggerUi()");
return;
@ -57,7 +62,7 @@ function initSwaggerUi() {
}
}
console.log(swaggerSettings);
console.log('swaggerSettings', swaggerSettings);
for (var p in swaggerSettings) {
if (swaggerSettings.hasOwnProperty(p)) {
swaggerConfig[p] = swaggerSettings[p];
@ -66,7 +71,7 @@ function initSwaggerUi() {
window.ui = SwaggerUIBundle(swaggerConfig);
var oauth2Config = JSON.parse(document.getElementById('oauth2-config').innerHTML);
console.log(oauth2Config);
console.log('oauth2Config', oauth2Config);
window.ui.initOAuth(oauth2Config);
}

View File

@ -69,8 +69,8 @@
<a id="oauth2-redirect-url" href="{% static 'drf-yasg/swagger-ui-dist/oauth2-redirect.html' %}" class="hidden"></a>
<div id="django-session-auth" class="hidden">
{% if USE_SESSION_AUTH %}
{% if USE_SESSION_AUTH %}
<div id="django-session-auth" class="hidden">
{% csrf_token %}
{% if request.user.is_authenticated %}
<div class="hello">
@ -91,8 +91,8 @@
</a>
</div>
{% endif %}
{% endif %}
</div>
</div>
{% endif %}
</body>
</html>