Closed vserpokryl closed 10 months ago
Yeah, hmm. It fixes it for backwards compatibility. But what if someone provides an svg as logo?
@Uzlopak
Yeah, hmm. It fixes it for backwards compatibility. But what if someone provides an svg as logo?
It's fine, because user always provides content as buffer/string, and then this content serialize to base64
@fastify/swagger-ui/lib/swagger-initializer.js
const logoBase64 = Buffer.from(opts.logo.content).toString('base64')
const logoData = `data:${opts.logo.type};base64,${logoBase64}`
@fastify/swagger-ui/types/index.d.ts
type FastifySwaggerUILogo = {
type: string;
content: string | Buffer;
}
@Uzlopak the src replacement logic in the img was the same before, nothing has changed here
@Uzlopak Small example:
import fastify from 'fastify';
import swagger from '@fastify/swagger';
import swaggerUI from '@fastify/swagger-ui';
const app = fastify({ logger: true });
(async () => {
const response = await fetch('https://www.reshot.com/preview-assets/icons/CZ2NMXUGQ8/code-CZ2NMXUGQ8.svg');
const content = await response.arrayBuffer();
app.register(swagger);
app.register(swaggerUI, {
routePrefix: '/docs',
logo: {
content,
type: 'image/svg+xml',
},
});
await app.listen({ host: '127.0.0.1', port: 3001 });
})();
CI using yarn failed
Could we add a test to avoid regression for next swaggerUI bumps?
@Eomm lib/swagger-initializer.js
returns custom initializer as js code
To test this feature, we need to be able to launch a browser that displays the full page
This requires additional dependencies, for example selenium-webdriver
I was thinking about Playwright if you are willing to try it. But yeah, we can open a new issue for this
Checklist
npm run test
andnpm run benchmark