| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
"use strict"; |
| 8 |
|
| 9 |
var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname; |
| 10 |
var specURL = currentPath + '?format=openapi'; |
| 11 |
var redoc = document.createElement("redoc"); |
| 12 |
|
| 13 |
var redocSettings = JSON.parse(document.getElementById('redoc-settings').innerHTML); |
| 14 |
if (redocSettings.url) { |
| 15 |
specURL = redocSettings.url; |
| 16 |
} |
| 17 |
delete redocSettings.url; |
| 18 |
if (redocSettings.fetchSchemaWithQuery) { |
| 19 |
var query = new URLSearchParams(window.location.search || '').entries(); |
| 20 |
var url = specURL.split('?'); |
| 21 |
var usp = new URLSearchParams(url[1] || ''); |
| 22 |
for (var it = query.next(); !it.done; it = query.next()) { |
| 23 |
usp.set(it.value[0], it.value[1]); |
| 24 |
} |
| 25 |
url[1] = usp.toString(); |
| 26 |
specURL = url[1] ? url.join('?') : url[0]; |
| 27 |
} |
| 28 |
delete redocSettings.fetchSchemaWithQuery; |
| 29 |
|
| 30 |
redoc.setAttribute("spec-url", specURL); |
| 31 |
|
| 32 |
function camelToKebab(str) { |
| 33 |
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); |
| 34 |
} |
| 35 |
|
| 36 |
for (var p in redocSettings) { |
| 37 |
if (redocSettings.hasOwnProperty(p)) { |
| 38 |
if (redocSettings[p] !== null && redocSettings[p] !== undefined && redocSettings[p] !== false) { |
| 39 |
redoc.setAttribute(camelToKebab(p), redocSettings[p].toString()); |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
document.body.replaceChild(redoc, document.getElementById('redoc-placeholder')); |
| 45 |
|
| 46 |
function hideEmptyVersion() { |
| 47 |
|
| 48 |
var apiVersion = document.querySelector('span.api-info-version') || document.querySelector('div.api-info span'); |
| 49 |
if (!apiVersion) { |
| 50 |
console.log("WARNING: could not find API versionString element (span.api-info-version)"); |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
var versionString = apiVersion.innerText; |
| 55 |
if (versionString) { |
| 56 |
|
| 57 |
versionString = versionString.replace(/ /g, ''); |
| 58 |
versionString = versionString.replace(/(^\()|(\)$)/g, ''); |
| 59 |
} |
| 60 |
|
| 61 |
if (!versionString) { |
| 62 |
|
| 63 |
apiVersion.classList.add("hidden"); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
if (document.querySelector('span.api-info-version') || document.querySelector('div.api-info span')) { |
| 68 |
hideEmptyVersion(); |
| 69 |
} |
| 70 |
else { |
| 71 |
insertionQ('span.api-info-version').every(hideEmptyVersion); |
| 72 |
insertionQ('div.api-info span').every(hideEmptyVersion); |
| 73 |
} |