Projektstart

This commit is contained in:
2026-01-22 15:49:12 +01:00
parent 7212eb6f7a
commit 57e5f652f8
10637 changed files with 2598792 additions and 64 deletions

View File

@@ -0,0 +1,37 @@
'use strict'
function indexHtml (opts) {
const hasLeadingSlash = /^\//.test(opts.prefix)
return (url) => {
const hasTrailingSlash = /\/$/.test(url)
const prefix = hasTrailingSlash ? `.${opts.staticPrefix}` : `${hasLeadingSlash ? '.' : ''}${opts.prefix}${opts.staticPrefix}`
return `<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>${opts.theme?.title || 'Swagger UI'}</title>
<link rel="stylesheet" type="text/css" href="${prefix}/swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="${prefix}/index.css" />
${opts.theme && opts.theme.css ? opts.theme.css.map(css => `<link rel="stylesheet" type="text/css" href="${prefix}/theme/${css.filename}" />\n`).join('') : ''}
${opts.theme && opts.theme.favicon
? opts.theme.favicon.map(favicon => `<link rel="${favicon.rel}" type="${favicon.type}" href="${prefix}/theme/${favicon.filename}" sizes="${favicon.sizes}" />\n`).join('')
: `
<link rel="icon" type="image/png" href="${prefix}/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="${prefix}/favicon-16x16.png" sizes="16x16" />
`}
</head>
<body>
<div id="swagger-ui"></div>
<script src="${prefix}/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="${prefix}/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="${prefix}/swagger-initializer.js" charset="UTF-8"> </script>
${opts.theme && opts.theme.js ? opts.theme.js.map(js => `<script src="${prefix}/theme/${js.filename}" charset="UTF-8"> </script>\n`).join('') : ''}
</body>
</html>
`
}
}
module.exports = indexHtml

219
backend/node_modules/@fastify/swagger-ui/lib/routes.js generated vendored Normal file
View File

@@ -0,0 +1,219 @@
'use strict'
const path = require('node:path')
const yaml = require('yaml')
const fastifyStatic = require('@fastify/static')
const rfdc = require('rfdc')()
const swaggerInitializer = require('./swagger-initializer')
const indexHtml = require('./index-html')
// URI prefix to separate static assets for swagger UI
const staticPrefix = '/static'
function fastifySwagger (fastify, opts, done) {
let staticCSP = false
if (opts.staticCSP === true) {
const csp = fastify.swaggerCSP
staticCSP = `default-src 'self'; base-uri 'self'; font-src 'self' https: data:; frame-ancestors 'self'; img-src 'self' data: validator.swagger.io; object-src 'none'; script-src 'self' ${csp.script.join(' ')}; script-src-attr 'none'; style-src 'self' https: ${csp.style.join(' ')}; upgrade-insecure-requests;`
}
if (typeof opts.staticCSP === 'string') {
staticCSP = opts.staticCSP
}
if (typeof opts.staticCSP === 'object' && opts.staticCSP !== null) {
staticCSP = ''
Object.keys(opts.staticCSP).forEach(function (key) {
const value = Array.isArray(opts.staticCSP[key]) ? opts.staticCSP[key].join(' ') : opts.staticCSP[key]
staticCSP += `${key.toLowerCase()} ${value}; `
})
}
if (typeof staticCSP === 'string' || typeof opts.transformStaticCSP === 'function') {
fastify.addHook('onSend', function (request, reply, payload, done) {
// set static csp when it is passed
if (typeof staticCSP === 'string') {
reply.header('content-security-policy', staticCSP.trim())
}
// mutate the header when it is passed
const header = reply.getHeader('content-security-policy')
if (header && typeof opts.transformStaticCSP === 'function') {
reply.header('content-security-policy', opts.transformStaticCSP(header))
}
done()
})
}
const hooks = Object.create(null)
if (opts.hooks) {
const additionalHooks = [
'onRequest',
'preHandler'
]
for (const hook of additionalHooks) {
hooks[hook] = opts.hooks[hook]
}
}
if (opts.theme) {
const themePrefix = `${staticPrefix}/theme`
if (opts.theme.css) {
for (const cssFile of opts.theme.css) {
fastify.route({
url: `${themePrefix}/${cssFile.filename}`,
method: 'GET',
schema: { hide: true },
...hooks,
handler: (req, reply) => {
reply
.header('content-type', 'text/css; charset=UTF-8')
.send(cssFile.content)
}
})
}
}
if (opts.theme.js) {
for (const jsFile of opts.theme.js) {
fastify.route({
url: `${themePrefix}/${jsFile.filename}`,
method: 'GET',
schema: { hide: true },
...hooks,
handler: (req, reply) => {
reply
.header('content-type', 'application/javascript; charset=utf-8')
.send(jsFile.content)
}
})
}
}
if (opts.theme.favicon) {
for (const favicon of opts.theme.favicon) {
fastify.route({
url: `${themePrefix}/${favicon.filename}`,
method: 'GET',
schema: { hide: true },
...hooks,
handler: (req, reply) => {
reply
.header('content-type', favicon.type)
.send(favicon.content)
}
})
}
}
}
const indexHtmlContent = indexHtml({ ...opts, staticPrefix })
fastify.route({
url: '/',
method: 'GET',
schema: { hide: true },
...hooks,
handler: (req, reply) => {
reply
.header('content-type', 'text/html; charset=utf-8')
.send(indexHtmlContent(req.url)) // trailing slash alters the relative urls generated in the html
}
})
fastify.route({
url: `${staticPrefix}/index.html`,
method: 'GET',
schema: { hide: true },
...hooks,
handler: (req, reply) => {
reply.redirect(req.url.replace(/\/static\/index\.html$/, '/'))
}
})
const swaggerInitializerContent = swaggerInitializer(opts)
fastify.route({
url: `${staticPrefix}/swagger-initializer.js`,
method: 'GET',
schema: { hide: true },
...hooks,
handler: (req, reply) => {
reply
.header('content-type', 'application/javascript; charset=utf-8')
.send(swaggerInitializerContent)
}
})
const hasTransformSpecificationFn = typeof opts.transformSpecification === 'function'
const shouldCloneSwaggerObject = opts.transformSpecificationClone ?? true
const transformSpecification = opts.transformSpecification
fastify.route({
url: '/json',
method: 'GET',
schema: { hide: true },
...hooks,
handler: hasTransformSpecificationFn
? shouldCloneSwaggerObject
? function (req, reply) {
reply.send(transformSpecification(rfdc(fastify.swagger()), req, reply))
}
: function (req, reply) {
reply.send(transformSpecification(fastify.swagger(), req, reply))
}
: function (req, reply) {
reply.send(fastify.swagger())
}
})
fastify.route({
url: '/yaml',
method: 'GET',
schema: { hide: true },
...hooks,
handler: hasTransformSpecificationFn
? shouldCloneSwaggerObject
? function (req, reply) {
reply
.type('application/x-yaml')
.send(yaml.stringify(transformSpecification(rfdc(fastify.swagger()), req, reply)))
}
: function (req, reply) {
reply
.type('application/x-yaml')
.send(yaml.stringify(transformSpecification(fastify.swagger(), req, reply)))
}
: function (req, reply) {
reply
.type('application/x-yaml')
.send(fastify.swagger({ yaml: true }))
}
})
// serve swagger-ui with the help of @fastify/static
fastify.register(fastifyStatic, {
root: opts.baseDir || path.join(__dirname, '..', 'static'),
prefix: staticPrefix,
decorateReply: false
})
if (opts.baseDir) {
fastify.register(fastifyStatic, {
root: opts.baseDir,
serve: false
})
// Handler for external documentation files passed via $ref
fastify.route({
url: '/*',
method: 'GET',
schema: { hide: true },
...hooks,
handler: function (req, reply) {
const file = req.params['*']
reply.sendFile(file)
}
})
}
done()
}
module.exports = fastifySwagger

View File

@@ -0,0 +1,69 @@
'use strict'
function serialize (value) {
switch (typeof value) {
case 'bigint':
return value.toString() + 'n'
case 'boolean':
return value ? 'true' : 'false'
case 'function':
return value.toString()
case 'number':
return '' + value
case 'object':
if (value === null) {
return 'null'
} else if (Array.isArray(value)) {
return serializeArray(value)
} else if (value instanceof RegExp) {
return `/${value.source}/${value.flags}`
} else if (value instanceof Date) {
return `new Date(${value.getTime()})`
} else if (value instanceof Set) {
return `new Set(${serializeArray(Array.from(value))})`
} else if (value instanceof Map) {
return `new Map(${serializeArray(Array.from(value))})`
} else {
return serializeObject(value)
}
case 'string':
return JSON.stringify(value)
case 'symbol':
return serializeSymbol(value)
case 'undefined':
return 'undefined'
}
}
const symbolRE = /Symbol\((.+)\)/
function serializeSymbol (value) {
return symbolRE.test(value.toString())
? `Symbol("${value.toString().match(symbolRE)[1]}")`
: 'Symbol()'
}
function serializeArray (value) {
let result = '['
const il = value.length
const last = il - 1
for (let i = 0; i < il; ++i) {
result += serialize(value[i])
i !== last && (result += ',')
}
return result + ']'
}
function serializeObject (value) {
let result = '{'
const keys = Object.keys(value)
let i = 0
const il = keys.length
const last = il - 1
for (; i < il; ++i) {
const key = keys[i]
result += `"${key}":${serialize(value[key])}`
i !== last && (result += ',')
}
return result + '}'
}
module.exports = serialize

View File

@@ -0,0 +1,74 @@
'use strict'
const serialize = require('./serialize')
function swaggerInitializer (opts) {
const logoBase64 = Buffer.from(opts.logo.content).toString('base64')
const logoData = `data:${opts.logo.type};base64,${logoBase64}`
return `window.onload = function () {
function waitForElement(selector) {
return new Promise(resolve => {
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,
subtree: true
});
});
}
function resolveUrl(url) {
var currentHref = window.location.href;
currentHref = currentHref.split('#', 1)[0];
currentHref = currentHref.endsWith('/') ? currentHref : currentHref + '/';
var anchor = document.createElement('a');
anchor.href = currentHref + url;
return anchor.href
}
const config = ${serialize(opts.uiConfig)}
const resConfig = Object.assign({}, {
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
validatorUrl: ${serialize(opts.validatorUrl || null)},
}, config, {
url: resolveUrl('./json'),
oauth2RedirectUrl: resolveUrl('./static/oauth2-redirect.html')
});
const ui = SwaggerUIBundle(resConfig)
const logoData = '${logoData}'
if (logoData && resConfig.layout === 'StandaloneLayout') {
waitForElement('#swagger-ui > section > div.topbar > div > div > a').then((link) => {
const img = document.createElement('img')
img.height = 40
img.src = logoData
link.innerHTML = ''
link.appendChild(img)
})
}
ui.initOAuth(${serialize(opts.initOAuth)})
}`
}
module.exports = swaggerInitializer