parent
18ff51a025
commit
dfe06b5c95
|
|
@ -248,6 +248,14 @@ Re-fetch the OpenAPI document without credentials after authorization is removed
|
|||
**Default**: :python:`'False` |br|
|
||||
*Maps to parameter*: -
|
||||
|
||||
FETCH_SCHEMA_WITH_QUERY
|
||||
-----------------------
|
||||
|
||||
Fetch the OpenAPI document using the query parameters passed to the swagger-ui page request.
|
||||
|
||||
**Default**: :python:`'True` |br|
|
||||
*Maps to parameter*: -
|
||||
|
||||
OPERATIONS_SORTER
|
||||
-----------------
|
||||
|
||||
|
|
@ -441,5 +449,13 @@ Show required properties first ordered in the same order as in required array.
|
|||
**Default**: :python:`False` |br|
|
||||
*Maps to attribute*: ``requiredPropsFirst``
|
||||
|
||||
FETCH_SCHEMA_WITH_QUERY
|
||||
-----------------------
|
||||
|
||||
Fetch the OpenAPI document using the query parameters passed to the ReDoc page request.
|
||||
|
||||
**Default**: :python:`'True` |br|
|
||||
*Maps to parameter*: -
|
||||
|
||||
|
||||
.. _FORCE_SCRIPT_NAME: https://docs.djangoproject.com/en/2.0/ref/settings/#force-script-name
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ SWAGGER_DEFAULTS = {
|
|||
'PERSIST_AUTH': False,
|
||||
'REFETCH_SCHEMA_WITH_AUTH': False,
|
||||
'REFETCH_SCHEMA_ON_LOGOUT': False,
|
||||
'FETCH_SCHEMA_WITH_QUERY': True,
|
||||
|
||||
'OPERATIONS_SORTER': None,
|
||||
'TAGS_SORTER': None,
|
||||
|
|
@ -77,6 +78,7 @@ REDOC_DEFAULTS = {
|
|||
'PATH_IN_MIDDLE': False,
|
||||
'NATIVE_SCROLLBARS': False,
|
||||
'REQUIRED_PROPS_FIRST': False,
|
||||
'FETCH_SCHEMA_WITH_QUERY': True,
|
||||
}
|
||||
|
||||
IMPORT_STRINGS = [
|
||||
|
|
|
|||
|
|
@ -137,6 +137,7 @@ class SwaggerUIRenderer(_UIRenderer):
|
|||
'persistAuth': swagger_settings.PERSIST_AUTH,
|
||||
'refetchWithAuth': swagger_settings.REFETCH_SCHEMA_WITH_AUTH,
|
||||
'refetchOnLogout': swagger_settings.REFETCH_SCHEMA_ON_LOGOUT,
|
||||
'fetchSchemaWithQuery': swagger_settings.FETCH_SCHEMA_WITH_QUERY,
|
||||
}
|
||||
|
||||
data = filter_none(data)
|
||||
|
|
@ -164,6 +165,7 @@ class ReDocRenderer(_UIRenderer):
|
|||
'pathInMiddlePanel': redoc_settings.PATH_IN_MIDDLE,
|
||||
'nativeScrollbars': redoc_settings.NATIVE_SCROLLBARS,
|
||||
'requiredPropsFirst': redoc_settings.REQUIRED_PROPS_FIRST,
|
||||
'fetchSchemaWithQuery': redoc_settings.FETCH_SCHEMA_WITH_QUERY,
|
||||
}
|
||||
|
||||
return filter_none(data)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,20 @@ var redoc = document.createElement("redoc");
|
|||
var redocSettings = JSON.parse(document.getElementById('redoc-settings').innerHTML);
|
||||
if (redocSettings.url) {
|
||||
specURL = redocSettings.url;
|
||||
delete redocSettings.url;
|
||||
}
|
||||
delete redocSettings.url;
|
||||
if (redocSettings.fetchSchemaWithQuery) {
|
||||
var query = new URLSearchParams(window.location.search).entries();
|
||||
var url = specURL.split('?');
|
||||
var usp = new URLSearchParams(url[1]);
|
||||
for (var it = query.next(); !it.done; it = query.next()) {
|
||||
usp.set(it.value[0], it.value[1]);
|
||||
}
|
||||
url[1] = usp.toString();
|
||||
specURL = url[1] ? url.join('?') : url[0];
|
||||
}
|
||||
delete redocSettings.fetchSchemaWithQuery;
|
||||
|
||||
redoc.setAttribute("spec-url", specURL);
|
||||
|
||||
function camelToKebab(str) {
|
||||
|
|
@ -36,8 +48,8 @@ function hideEmptyVersion() {
|
|||
var versionString = apiVersion.innerText;
|
||||
if (versionString) {
|
||||
// trim spaces and surrounding ()
|
||||
versionString = versionString.replace(/ /g,'');
|
||||
versionString = versionString.replace(/(^\()|(\)$)/g,'');
|
||||
versionString = versionString.replace(/ /g, '');
|
||||
versionString = versionString.replace(/(^\()|(\)$)/g, '');
|
||||
}
|
||||
|
||||
if (!versionString) {
|
||||
|
|
|
|||
|
|
@ -91,9 +91,11 @@ function initSwaggerUiConfig(swaggerSettings, oauth2Settings) {
|
|||
var persistAuth = swaggerSettings.persistAuth;
|
||||
var refetchWithAuth = swaggerSettings.refetchWithAuth;
|
||||
var refetchOnLogout = swaggerSettings.refetchOnLogout;
|
||||
var fetchSchemaWithQuery = swaggerSettings.fetchSchemaWithQuery;
|
||||
delete swaggerSettings['persistAuth'];
|
||||
delete swaggerSettings['refetchWithAuth'];
|
||||
delete swaggerSettings['refetchOnLogout'];
|
||||
delete swaggerSettings['fetchSchemaWithQuery'];
|
||||
|
||||
for (var p in swaggerSettings) {
|
||||
if (swaggerSettings.hasOwnProperty(p)) {
|
||||
|
|
@ -101,6 +103,15 @@ function initSwaggerUiConfig(swaggerSettings, oauth2Settings) {
|
|||
}
|
||||
}
|
||||
|
||||
if (fetchSchemaWithQuery) {
|
||||
// only add query params from document for the first spec request
|
||||
// this ensures we otherwise honor the spec selector box which might be manually modified
|
||||
var query = new URLSearchParams(window.location.search).entries();
|
||||
for (var it = query.next(); !it.done; it = query.next()) {
|
||||
swaggerUiConfig.url = setQueryParam(swaggerUiConfig.url, it.value[0], it.value[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (persistAuth || refetchWithAuth) {
|
||||
var hookedAuth = false;
|
||||
if (persistAuth) {
|
||||
|
|
@ -132,7 +143,6 @@ function initSwaggerUiConfig(swaggerSettings, oauth2Settings) {
|
|||
var headers = request.headers || {};
|
||||
if (request.loadSpec) {
|
||||
var newUrl = request.url;
|
||||
|
||||
if (refetchWithAuth) {
|
||||
newUrl = applyAuth(savedAuth, newUrl, headers) || newUrl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
{% block main_scripts %}
|
||||
<script src="{% static 'drf-yasg/insQ.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/url-polyfill.min.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/redoc-init.js' %}"></script>
|
||||
<script src="{% static 'drf-yasg/redoc/redoc.min.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
|
|
|||
Loading…
Reference in New Issue