Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ It's possible to override the logo displayed in the top bar by specifying:
await fastify.register(require('@fastify/swagger-ui'), {
logo: {
type: 'image/png',
content: Buffer.from('iVBOR...', 'base64')
content: Buffer.from('iVBOR...', 'base64'),
href: {
url: '/documentation',
target_blank: true,
}
},
theme: {
favicon: [
Expand Down
3 changes: 3 additions & 0 deletions lib/swagger-initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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 logoHref = opts.logo.href

return `window.onload = function () {
function waitForElement(selector) {
Expand Down Expand Up @@ -62,6 +63,8 @@ function swaggerInitializer (opts) {
const img = document.createElement('img')
img.height = 40
img.src = logoData
img.href = logoHref || resolveUrl('/')
logoTarget && (img.target = logoTarget)
link.innerHTML = ''
link.appendChild(img)
})
Expand Down
2 changes: 2 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ declare namespace fastifySwaggerUi {
type FastifySwaggerUILogo = {
type: string;
content: string | Buffer;
href?: string;
target?: '_blank' | '_parent' | '_self' | '_top';
}

type SupportedHTTPMethods = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace";
Expand Down