@unleash/express-openapi
Advanced tools
Comparing version 0.2.0 to 0.2.1-beta.0
@@ -6,4 +6,19 @@ 'use strict' | ||
module.exports.serveSwaggerUI = function serveSwaggerUI (documentUrl) { | ||
return [serve(path.resolve(require.resolve('swagger-ui-dist'), '..'), { index: false }), function renderSwaggerHtml (req, res) { | ||
res.type('html').send(renderHtmlPage('Swagger UI', ` | ||
return [serve(path.resolve(require.resolve('swagger-ui-dist'), '..'), { index: false }), | ||
function returnUiInit (req, res, next) { | ||
if (req.path.endsWith('/swagger-ui-init.js')) { | ||
res.type('.js') | ||
res.send(`window.onload = function () { | ||
window.ui = SwaggerUIBundle({ | ||
url: "${documentUrl}", | ||
dom_id: '#swagger-ui' | ||
}) | ||
} | ||
`) | ||
} else { | ||
next() | ||
} | ||
}, | ||
function renderSwaggerHtml (req, res) { | ||
res.type('html').send(renderHtmlPage('Swagger UI', ` | ||
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" > | ||
@@ -14,12 +29,6 @@ `, ` | ||
<script src="./swagger-ui-standalone-preset.js"></script> | ||
<script> | ||
window.onload = function () { | ||
window.ui = SwaggerUIBundle({ | ||
url: "${documentUrl}", | ||
dom_id: '#swagger-ui' | ||
}) | ||
} | ||
</script> | ||
<script src="./swagger-ui-init.js"></script> | ||
`)) | ||
}] | ||
} | ||
] | ||
} | ||
@@ -26,0 +35,0 @@ |
{ | ||
"name": "@unleash/express-openapi", | ||
"version": "0.2.0", | ||
"version": "0.2.1-beta.0", | ||
"description": "Middleware for generating OpenAPI/Swagger documentation for your Express app", | ||
@@ -5,0 +5,0 @@ "author": "@unleash", |
@@ -7,3 +7,1 @@ # unleash-express-openapi | ||
2. removes the redoc dependency which we don't use. | ||
The fork is not published to npm, and only used by https://github.com/Unleash/unleash. |
@@ -84,2 +84,14 @@ 'use strict' | ||
test('serves onload function in swagger-ui-init.js file', function (done) { | ||
const app = express() | ||
app.use(openapi().swaggerui) | ||
supertest(app) | ||
.get(`${openapi.defaultRoutePrefix}/swagger-ui-init.js`) | ||
.end((err, res) => { | ||
assert(!err, err) | ||
assert(res.text.includes('window.onload = function () {')) | ||
done() | ||
}) | ||
}) | ||
test('load routes from the express app', function (done) { | ||
@@ -86,0 +98,0 @@ const app = express() |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34066
15
997
7
3