Socket
Socket
Sign inDemoInstall

@fastify/swagger-ui

Package Overview
Dependencies
Maintainers
18
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/swagger-ui - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

.tap/processinfo/36bb6be8-5e9e-48b9-900b-d34d55d0e9cc.json

9

e2e/custom.test.js

@@ -81,2 +81,11 @@ 'use strict'

})
test('Check root UI with hash loads json spec', async ({ page }) => {
const jsonResponsePromise = page.waitForResponse(/json/)
await page.goto(`${URL_DOCUMENTATION}#default/get_example`)
// Check if the page has requested the json spec, and if so has it succeeded
const jsonResponse = await jsonResponsePromise
expect(jsonResponse.ok()).toBe(true)
})
})

55

lib/index-html.js
'use strict'
function indexHtml (opts) {
return (url) => `<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>${opts.theme?.title || 'Swagger UI'}</title>
<link rel="stylesheet" type="text/css" href="${url}${opts.staticPrefix}/swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="${url}${opts.staticPrefix}/index.css" />
${opts.theme && opts.theme.css ? opts.theme.css.map(css => `<link rel="stylesheet" type="text/css" href="${url}${opts.staticPrefix}/theme/${css.filename}" />\n`).join('') : ''}
${opts.theme && opts.theme.favicon
? opts.theme.favicon.map(favicon => `<link rel="${favicon.rel}" type="${favicon.type}" href="${url}${opts.staticPrefix}/theme/${favicon.filename}" sizes="${favicon.sizes}" />\n`).join('')
: `
<link rel="icon" type="image/png" href="${url}${opts.staticPrefix}/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="${url}${opts.staticPrefix}/favicon-16x16.png" sizes="16x16" />
`}
</head>
<body>
<div id="swagger-ui"></div>
<script src="${url}${opts.staticPrefix}/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="${url}${opts.staticPrefix}/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="${url}${opts.staticPrefix}/swagger-initializer.js" charset="UTF-8"> </script>
${opts.theme && opts.theme.js ? opts.theme.js.map(js => `<script src="${url}${opts.staticPrefix}/theme/${js.filename}" charset="UTF-8"> </script>\n`).join('') : ''}
</body>
</html>
`
return (hasTrailingSlash) => {
const prefix = hasTrailingSlash ? `.${opts.staticPrefix}` : `.${opts.prefix}${opts.staticPrefix}`
return `<!-- HTML for static distribution bundle build -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>${opts.theme?.title || 'Swagger UI'}</title>
<link rel="stylesheet" type="text/css" href="${prefix}/swagger-ui.css" />
<link rel="stylesheet" type="text/css" href="${prefix}/index.css" />
${opts.theme && opts.theme.css ? opts.theme.css.map(css => `<link rel="stylesheet" type="text/css" href="${prefix}/theme/${css.filename}" />\n`).join('') : ''}
${opts.theme && opts.theme.favicon
? opts.theme.favicon.map(favicon => `<link rel="${favicon.rel}" type="${favicon.type}" href="${prefix}/theme/${favicon.filename}" sizes="${favicon.sizes}" />\n`).join('')
: `
<link rel="icon" type="image/png" href="${prefix}/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href=".${opts.prefix}/favicon-16x16.png" sizes="16x16" />
`}
</head>
<body>
<div id="swagger-ui"></div>
<script src="${prefix}/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="${prefix}/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script src="${prefix}/swagger-initializer.js" charset="UTF-8"> </script>
${opts.theme && opts.theme.js ? opts.theme.js.map(js => `<script src="${prefix}/theme/${js.filename}" charset="UTF-8"> </script>\n`).join('') : ''}
</body>
</html>
`
}
}
module.exports = indexHtml

@@ -115,5 +115,6 @@ 'use strict'

handler: (req, reply) => {
const hasTrailingSlash = /\/$/.test(req.url)
reply
.header('content-type', 'text/html; charset=utf-8')
.send(indexHtmlContent(req.url.replace(/\/$/, ''))) // remove trailing slash, as staticPrefix has a leading slash
.send(indexHtmlContent(hasTrailingSlash)) // trailing slash alters the relative urls generated in the html
}

@@ -120,0 +121,0 @@ })

@@ -32,2 +32,3 @@ 'use strict'

var currentHref = window.location.href;
currentHref = currentHref.split('#', 1)[0];
currentHref = currentHref.endsWith('/') ? currentHref : currentHref + '/';

@@ -34,0 +35,0 @@ var anchor = document.createElement('a');

{
"name": "@fastify/swagger-ui",
"version": "4.0.0",
"version": "4.0.1",
"description": "Serve Swagger-ui for Fastify",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -551,6 +551,57 @@ 'use strict'

t.equal(res.payload.includes('href="/documentation/static/index.css"'), true)
t.equal(res.payload.includes('src="/documentation/static/theme/theme-js.js"'), true)
t.equal(res.payload.includes('href="/documentation/index.css"'), false)
t.equal(res.payload.includes('src="/documentation/theme/theme-js.js"'), false)
t.equal(res.payload.includes('href="./documentation/static/index.css"'), true)
t.equal(res.payload.includes('src="./documentation/static/theme/theme-js.js"'), true)
t.equal(res.payload.includes('href="./documentation/index.css"'), false)
t.equal(res.payload.includes('src="./documentation/theme/theme-js.js"'), false)
})
test('/documentation/ should display index html with correct asset urls', async (t) => {
t.plan(4)
const fastify = Fastify()
await fastify.register(fastifySwagger, swaggerOption)
await fastify.register(fastifySwaggerUi, { theme: { js: [{ filename: 'theme-js.js' }] } })
const res = await fastify.inject({
method: 'GET',
url: '/documentation/'
})
t.equal(res.payload.includes('href="./static/index.css"'), true)
t.equal(res.payload.includes('src="./static/theme/theme-js.js"'), true)
t.equal(res.payload.includes('href="./index.css"'), false)
t.equal(res.payload.includes('src="./theme/theme-js.js"'), false)
})
test('/docs should display index html with correct asset urls when documentation prefix is set', async (t) => {
t.plan(4)
const fastify = Fastify()
await fastify.register(fastifySwagger, swaggerOption)
await fastify.register(fastifySwaggerUi, { theme: { js: [{ filename: 'theme-js.js' }] }, routePrefix: '/docs' })
const res = await fastify.inject({
method: 'GET',
url: '/docs'
})
t.equal(res.payload.includes('href="./docs/static/index.css"'), true)
t.equal(res.payload.includes('src="./docs/static/theme/theme-js.js"'), true)
t.equal(res.payload.includes('href="./docs/index.css"'), false)
t.equal(res.payload.includes('src="./docs/theme/theme-js.js"'), false)
})
test('/docs/ should display index html with correct asset urls when documentation prefix is set', async (t) => {
t.plan(4)
const fastify = Fastify()
await fastify.register(fastifySwagger, swaggerOption)
await fastify.register(fastifySwaggerUi, { theme: { js: [{ filename: 'theme-js.js' }] }, routePrefix: '/docs' })
const res = await fastify.inject({
method: 'GET',
url: '/docs/'
})
t.equal(res.payload.includes('href="./static/index.css"'), true)
t.equal(res.payload.includes('src="./static/theme/theme-js.js"'), true)
t.equal(res.payload.includes('href="./index.css"'), false)
t.equal(res.payload.includes('src="./theme/theme-js.js"'), false)
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc