Update ReDoc settings

This commit is contained in:
Cristi Vîjdea
2018-09-10 01:39:43 +03:00
parent 10abf46597
commit 4bac38e67b
5 changed files with 40 additions and 16 deletions
+3 -1
View File
@@ -67,10 +67,12 @@ SWAGGER_DEFAULTS = {
REDOC_DEFAULTS = {
'SPEC_URL': None,
'LAZY_RENDERING': True,
'LAZY_RENDERING': False,
'HIDE_HOSTNAME': False,
'EXPAND_RESPONSES': 'all',
'PATH_IN_MIDDLE': False,
'NATIVE_SCROLLBARS': False,
'REQUIRED_PROPS_FIRST': False,
}
IMPORT_STRINGS = [
+5 -1
View File
@@ -1,3 +1,5 @@
import warnings
import six
from django.shortcuts import render, resolve_url
@@ -157,7 +159,9 @@ class ReDocRenderer(_UIRenderer):
'lazyRendering': redoc_settings.LAZY_RENDERING,
'hideHostname': redoc_settings.HIDE_HOSTNAME,
'expandResponses': redoc_settings.EXPAND_RESPONSES,
'pathInMiddle': redoc_settings.PATH_IN_MIDDLE,
'pathInMiddlePanel': redoc_settings.PATH_IN_MIDDLE,
'nativeScrollbars': redoc_settings.NATIVE_SCROLLBARS,
'requiredPropsFirst': redoc_settings.REQUIRED_PROPS_FIRST,
}
return filter_none(data)
+11 -8
View File
@@ -7,19 +7,22 @@ var redoc = document.createElement("redoc");
var redocSettings = JSON.parse(document.getElementById('redoc-settings').innerHTML);
if (redocSettings.url) {
specURL = redocSettings.url;
delete redocSettings.url;
}
redoc.setAttribute("spec-url", specURL);
if (redocSettings.lazyRendering) {
redoc.setAttribute("lazy-rendering", '');
function camelToKebab(str) {
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
}
if (redocSettings.pathInMiddle) {
redoc.setAttribute("path-in-middle-panel", '');
for (var p in redocSettings) {
if (redocSettings.hasOwnProperty(p)) {
if (redocSettings[p] !== null && redocSettings[p] !== undefined && redocSettings[p] !== false) {
redoc.setAttribute(camelToKebab(p), redocSettings[p].toString());
}
}
}
if (redocSettings.hideHostname) {
redoc.setAttribute("hide-hostname", '');
}
redoc.setAttribute("expand-responses", redocSettings.expandResponses);
document.body.appendChild(redoc);
function hideEmptyVersion() {