@sigiljs-community/swagger-ui-plugin
Version:
Plugin for SigilJS framework, that generates and serves Swagger UI at a configurable endpoint
4 lines (3 loc) • 1.65 kB
JavaScript
;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const y=require("@sigiljs/sigil/utils"),p=require("./swaggerHtmlTemplate.js");function r(t,l,c){const n=new RegExp(`<%\\s*${l}\\s*%>`,"g");return t.replace(n,c)}async function $(t){let l="",c="",n="",u="";t.customCss&&(t.customCss.startsWith("http")?l=`<link rel="stylesheet" href="${t.customCss}" />`:c=`<style>${t.customCss}</style>`),t.customJs&&(t.customJs.startsWith("http")?n=`<script src="${t.customJs}"><\/script>`:u=`<script>${t.customJs}<\/script>`);let e=p.swaggerHtmlTemplate;e=r(e,"robotsMetaString",Object.entries(t.htmlMeta??{}).map(([g,o])=>`<meta content="${o}" property="${g}" />`).join(`
`)),e=r(e,"title",t.title||"Swagger Documentation");let i="";t.favIcon&&(i=(Array.isArray(t.favIcon)?t.favIcon:[t.favIcon]).map(s=>{const m=typeof s=="string"?s:s.url,a=m.includes(".")?m.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(`
`)),e=r(e,"favIconString",i),e=e.replace('"<% swaggerInitOptions %>"',y.jsonStringify(t.swaggerInitOptions||{},{fallback:"{}"})),e=r(e,"customJs",n),e=r(e,"customJsString",u);const f=t.allowExplorer===!0?"":".swagger-ui .topbar .download-url-wrapper { display: none }";return e=r(e,"customCss",l),e=r(e,"customCssString",`<style>${f}</style>`+c),e=r(e,"basePath",t.base),e=r(e,"coreStylesUrl",t.swaggerStylesheet||"https://unpkg.com/swagger-ui-dist@5/swagger-ui.css"),e}exports.default=$;