@sigiljs-community/swagger-ui-plugin
Version:
Plugin for SigilJS framework, that generates and serves Swagger UI at a configurable endpoint
25 lines (24 loc) • 1.78 kB
JavaScript
import { jsonStringify as p } from "@sigiljs/sigil/utils";
import { swaggerHtmlTemplate as y } from "./swaggerHtmlTemplate.mjs";
function r(e, c, l) {
const n = new RegExp(`<%\\s*${c}\\s*%>`, "g");
return e.replace(n, l);
}
async function w(e) {
let c = "", l = "", n = "", i = "";
e.customCss && (e.customCss.startsWith("http") ? c = `<link rel="stylesheet" href="${e.customCss}" />` : l = `<style>${e.customCss}</style>`), e.customJs && (e.customJs.startsWith("http") ? n = `<script src="${e.customJs}"><\/script>` : i = `<script>${e.customJs}<\/script>`);
let t = y;
t = r(t, "robotsMetaString", Object.entries(e.htmlMeta ?? {}).map(([m, o]) => `<meta content="${o}" property="${m}" />`).join(`
`)), t = r(t, "title", e.title || "Swagger Documentation");
let u = "";
e.favIcon && (u = (Array.isArray(e.favIcon) ? e.favIcon : [e.favIcon]).map((s) => {
const g = typeof s == "string" ? s : s.url, a = g.includes(".") ? g.split(".").slice(-1)[0] : "x-icon";
return typeof s == "string" ? `<link rel="icon" type="image/${a}" href="${s}" />` : s.size ? `<link rel="icon" type="${s.type || a}" href="${s}" sizes="${s.size}x${s.size}" />` : `<link rel="icon" type="${s.type || a}" href="${s}" />`;
}).join(`
`)), t = r(t, "favIconString", u), t = t.replace('"<% swaggerInitOptions %>"', p(e.swaggerInitOptions || {}, { fallback: "{}" })), t = r(t, "customJs", n), t = r(t, "customJsString", i);
const f = e.allowExplorer === !0 ? "" : ".swagger-ui .topbar .download-url-wrapper { display: none }";
return t = r(t, "customCss", c), t = r(t, "customCssString", `<style>${f}</style>` + l), t = r(t, "basePath", e.base), t = r(t, "coreStylesUrl", e.swaggerStylesheet || "https://unpkg.com/swagger-ui-dist@5/swagger-ui.css"), t;
}
export {
w as default
};