Aktueller Stand

This commit is contained in:
2026-01-22 19:05:45 +01:00
parent 85dee61a4d
commit e280e4eadb
1967 changed files with 397327 additions and 74093 deletions

View File

@@ -3,8 +3,11 @@
const serialize = require('./serialize')
function swaggerInitializer (opts) {
const logoBase64 = Buffer.from(opts.logo.content).toString('base64')
const logoData = `data:${opts.logo.type};base64,${logoBase64}`
const hasLogo = opts.logo && opts.logo.content !== undefined
const logoBase64 = hasLogo && Buffer.from(opts.logo.content).toString('base64')
const logoData = hasLogo && `data:${opts.logo.type};base64,${logoBase64}`
const logoHref = hasLogo && opts.logo.href
const logoTarget = hasLogo && opts.logo.target
return `window.onload = function () {
function waitForElement(selector) {
@@ -12,14 +15,14 @@ function swaggerInitializer (opts) {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
observer.observe(document.body, {
childList: true,
@@ -28,10 +31,10 @@ function swaggerInitializer (opts) {
});
}
function resolveUrl(url) {
var currentHref = window.location.href;
let currentHref = window.location.href;
currentHref = currentHref.split('#', 1)[0];
currentHref = currentHref.endsWith('/') ? currentHref : currentHref + '/';
var anchor = document.createElement('a');
const anchor = document.createElement('a');
anchor.href = currentHref + url;
return anchor.href
}
@@ -55,17 +58,22 @@ function swaggerInitializer (opts) {
});
const ui = SwaggerUIBundle(resConfig)
const logoData = '${logoData}'
if (logoData && resConfig.layout === 'StandaloneLayout') {
${logoData
? `
if (resConfig.layout === 'StandaloneLayout') {
// Replace the logo
waitForElement('#swagger-ui > section > div.topbar > div > div > a').then((link) => {
const img = document.createElement('img')
img.height = 40
img.src = logoData
img.src = '${logoData}'
${logoHref ? `img.href = '${logoHref}'` : 'img.href = resolveUrl(\'/\')'}
${logoTarget ? `img.target = '${logoTarget}'` : ''}
link.innerHTML = ''
link.appendChild(img)
})
}
}`
: ''}
ui.initOAuth(${serialize(opts.initOAuth)})
}`