fastify / fastify-swagger-ui

Serve Swagger-UI for Fastify
MIT License
132 stars 40 forks source link

Ability to set custom logo is broken #92

Closed vserpokryl closed 10 months ago

vserpokryl commented 10 months ago

Prerequisites

Fastify version

4.24

Plugin version

1.10

Node.js version

18.x

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.0

Description

@fastify/swagger-ui@1.10.0 broke the ability to set custom logo It's because fastify/swagger-ui/lib/swagger-initializer.js has selector for image like '#swagger-ui > section > div.topbar > div > div > a > img', but new version of swagger-ui has svg logo, not img Full code:

if (logoData && resConfig.layout === 'StandaloneLayout') {
  const img = document.querySelector('#swagger-ui > section > div.topbar > div > div > a > img')
  img.src = logoData
}

Fix code (example):

if (logoData && resConfig.layout === 'StandaloneLayout') {
  const link = document.querySelector('#swagger-ui > section > div.topbar > div > div > a');
  const img = document.createElement('img');
  img.height = 40;
  img.src = logoData;
  link.innerHTML = '';
  link.appendChild(img);
}

Steps to Reproduce

// Default logo in @fastify/swagger-ui@1.9.0 is Fastify, but from v1.10.0 default logo is swagger

import swaggerUI from '@fastify/swagger-ui';

fastify.register(swaggerUI, {
  logo: {
    content: fs.readFileSync(path.resolve(__dirname, '../../static/logo.svg')),
    type: 'image/svg+xml',
  },
});

Expected Behavior

See the custom logo from ui configuration on the swagger documentation page

Eomm commented 10 months ago

Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.