Socket
Socket
Sign inDemoInstall

restify-swagger-jsdoc

Package Overview
Dependencies
146
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.0 to 3.2.1

21

js/index.js

@@ -12,5 +12,8 @@ "use strict";

}
function trimTrailingSlash(data) {
return data.replace(/\/+$/, '');
function trimTrailingChar(data, char = '/') {
return data.replace(new RegExp(`${char}+$`), '');
}
function fileNotFound(file, next) {
return next(new errors.NotFoundError(`File ${file} does not exist`));
}
function createSwaggerPage(options) {

@@ -29,3 +32,3 @@ if (!options.title) {

}
const swaggerUiPath = path.dirname(require.resolve('swagger-ui-dist'));
const swaggerUiPath = `${trimTrailingChar(path.dirname(require.resolve('swagger-ui-dist')), path.sep)}${path.sep}`;
const swaggerSpec = swaggerJSDoc({

@@ -38,3 +41,3 @@ swaggerDefinition: {

},
host: typeof options.host === 'string' ? trimTrailingSlash(options.host) : undefined,
host: typeof options.host === 'string' ? trimTrailingChar(options.host) : undefined,
basePath: typeof options.routePrefix === 'string' ? `/${options.routePrefix.replace(/^\/+/, '')}` : '/',

@@ -59,3 +62,3 @@ schemes: Array.isArray(options.schemes) ? options.schemes : undefined,

}
const publicPath = trimTrailingSlash(options.path);
const publicPath = trimTrailingChar(options.path);
options.server.get(`${publicPath}/swagger.json`, (req, res, next) => {

@@ -73,5 +76,9 @@ res.setHeader('Content-type', 'application/json');

const file = req.params['*'];
fs.readFile(path.resolve(swaggerUiPath, file), (err, content) => {
const filePath = path.resolve(swaggerUiPath, file);
if (filePath.indexOf(swaggerUiPath) !== 0) {
return fileNotFound(file, next);
}
fs.readFile(filePath, (err, content) => {
if (err) {
return next(new errors.NotFoundError(`File ${file} does not exist`));
return fileNotFound(file, next);
}

@@ -78,0 +85,0 @@ if (file === 'index.html') {

{
"name": "restify-swagger-jsdoc",
"version": "3.2.0",
"version": "3.2.1",
"description": "Create Swagger documentation page based on jsdoc",

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc