@fastify/swagger-ui
Advanced tools
Comparing version 2.1.0 to 3.0.0
@@ -10,2 +10,22 @@ 'use strict' | ||
return `window.onload = function () { | ||
function waitForElement(selector) { | ||
return new Promise(resolve => { | ||
if (document.querySelector(selector)) { | ||
return resolve(document.querySelector(selector)); | ||
} | ||
const observer = new MutationObserver(mutations => { | ||
if (document.querySelector(selector)) { | ||
observer.disconnect(); | ||
resolve(document.querySelector(selector)); | ||
} | ||
}); | ||
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336 | ||
observer.observe(document.body, { | ||
childList: true, | ||
subtree: true | ||
}); | ||
}); | ||
} | ||
function resolveUrl(url) { | ||
@@ -39,8 +59,9 @@ const anchor = document.createElement('a') | ||
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) | ||
waitForElement('#swagger-ui > section > div.topbar > div > div > a').then((link) => { | ||
const img = document.createElement('img') | ||
img.height = 40 | ||
img.src = logoData | ||
link.innerHTML = '' | ||
link.appendChild(img) | ||
}) | ||
} | ||
@@ -47,0 +68,0 @@ |
{ | ||
"name": "@fastify/swagger-ui", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Serve Swagger-ui for Fastify", | ||
@@ -55,2 +55,3 @@ "main": "index.js", | ||
"@playwright/test": "^1.39.0", | ||
"@tapjs/snapshot": "^1.2.17", | ||
"@types/node": "^20.1.1", | ||
@@ -62,8 +63,8 @@ "ajv": "^8.11.0", | ||
"standard": "^17.0.0", | ||
"swagger-ui-dist": "5.10.5", | ||
"tap": "^16.3.2", | ||
"swagger-ui-dist": "5.11.2", | ||
"tap": "^18.6.1", | ||
"tsd": "^0.30.0" | ||
}, | ||
"dependencies": { | ||
"@fastify/static": "^6.0.0", | ||
"@fastify/static": "^7.0.0", | ||
"fastify-plugin": "^4.0.0", | ||
@@ -70,0 +71,0 @@ "openapi-types": "^12.0.2", |
@@ -9,4 +9,2 @@ # @fastify/swagger-ui | ||
Supports Fastify versions `4.x`. | ||
![Demo](https://user-images.githubusercontent.com/52195/228162405-c85ad0d1-900d-442a-b712-7108d98d621f.png) | ||
@@ -20,2 +18,9 @@ | ||
### Compatibility | ||
| Plugin version | Fastify version | Swagger Plugin Version | | ||
| -------------- | --------------- | ---------------------- | | ||
| `^2.0.0` | `^4.0.0` | `^8.0.0` | | ||
| `^1.0.0` | `^4.0.0` | `^8.0.0` | | ||
<a name="usage"></a> | ||
@@ -22,0 +27,0 @@ ## Usage |
@@ -19,12 +19,17 @@ 'use strict' | ||
'swagger-ui-bundle.js', | ||
'swagger-ui-bundle.js.map', | ||
'swagger-ui-standalone-preset.js', | ||
'swagger-ui-standalone-preset.js.map', | ||
'swagger-ui.css', | ||
'swagger-ui.css.map', | ||
'swagger-ui.js', | ||
'swagger-ui.js.map' | ||
'swagger-ui.js' | ||
] | ||
filesToCopy.forEach(filename => { | ||
fse.copySync(`${swaggerUiAssetPath}/${filename}`, resolve(`./static/${filename}`)) | ||
fse.ensureFileSync(resolve(`./static/${filename}`)) | ||
const readableStream = fs.createReadStream(`${swaggerUiAssetPath}/${filename}`, 'utf8') | ||
const writableStream = fs.createWriteStream(resolve(`./static/${filename}`)) | ||
// Matches sourceMappingURL comments in .js and .css files | ||
const sourceMapRegex = new RegExp(String.raw`\/.# sourceMappingURL=${filename}.map(\*\/)?$`) | ||
readableStream.on('data', (chunk) => { | ||
// Copy file while removing sourceMappingURL comments | ||
writableStream.write(chunk.replace(sourceMapRegex, '')) | ||
}) | ||
}) | ||
@@ -31,0 +36,0 @@ |
@@ -1,1 +0,1 @@ | ||
{"script":["'sha256-4IiDsMH+GkJlxivIDNfi6qk0O5HPtzyvNwVT3Wt8TIw='"],"style":[]} | ||
{"script":[],"style":[]} |
@@ -135,3 +135,6 @@ 'use strict' | ||
t.strictSame(fastify.swagger(), JSON.parse(res.body)) | ||
const swagger = fastify.swagger() | ||
Object.getOwnPropertySymbols(swagger.definitions.User).forEach((symbol) => delete swagger.definitions.User[symbol]) | ||
t.strictSame(swagger, JSON.parse(res.body)) | ||
}) | ||
@@ -138,0 +141,0 @@ |
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 too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
91
14769
375
2499514
16
+ Added@fastify/static@7.0.4(transitive)
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedansi-regex@5.0.16.0.1(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcross-spawn@7.0.3(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedforeground-child@3.2.1(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedlru-cache@10.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedminipass@7.1.2(transitive)
+ Addedpackage-json-from-dist@1.0.0(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedpath-scurry@1.11.1(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
- Removed@fastify/static@6.12.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@8.1.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedminimatch@5.1.6(transitive)
- Removedonce@1.4.0(transitive)
- Removedp-limit@3.1.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedyocto-queue@0.1.0(transitive)
Updated@fastify/static@^7.0.0