Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-openapi-validator

Package Overview
Dependencies
Maintainers
1
Versions
281
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-openapi-validator - npm Package Compare versions

Comparing version 0.21.2 to 0.30.0

1

dist/framework/base.path.js

@@ -83,2 +83,3 @@ "use strict";

const path = u.substring(pathIdx);
// ensure a trailing slash is always present
return path[path.length - 1] === '/' ? path : path + '/';

@@ -85,0 +86,0 @@ }

@@ -0,4 +1,10 @@

import { Application } from 'express';
export interface OpenApiValidatorOpts {
apiSpecPath: string;
}
export declare function OpenApiValidator(options: OpenApiValidatorOpts): void;
export declare class OpenApiValidator {
private opts;
private context;
constructor(options: OpenApiValidatorOpts);
install(app: Application): void;
}

66

dist/index.js

@@ -8,37 +8,39 @@ "use strict";

const loggingKey = 'express-openapi-validator';
function OpenApiValidator(options) {
if (!options.apiSpecPath)
throw ono_1.default('apiSpecPath required');
const openApiContext = new openapi_context_1.OpenApiContext({ apiDoc: options.apiSpecPath });
const opts = {
enableObjectCoercion: true,
apiDoc: openApiContext.apiDoc,
};
this.opts = opts;
this.context = openApiContext;
}
exports.OpenApiValidator = OpenApiValidator;
OpenApiValidator.prototype.install = function (app) {
const pathParams = [];
for (const route of this.context.routes) {
if (route.pathParams.length > 0) {
pathParams.push(...route.pathParams);
}
class OpenApiValidator {
constructor(options) {
if (!options.apiSpecPath)
throw ono_1.default('apiSpecPath required');
const openApiContext = new openapi_context_1.OpenApiContext({ apiDoc: options.apiSpecPath });
const opts = {
enableObjectCoercion: true,
apiDoc: openApiContext.apiDoc,
};
this.opts = opts;
this.context = openApiContext;
}
// install param on routes with paths
for (const p of _.uniq(pathParams)) {
app.param(p, (req, res, next, value, name) => {
if (req.openapi.pathParams) {
// override path params
req.params[name] = req.openapi.pathParams[name] || req.params[name];
install(app) {
const pathParams = [];
for (const route of this.context.routes) {
if (route.pathParams.length > 0) {
pathParams.push(...route.pathParams);
}
next();
});
}
// install param on routes with paths
for (const p of _.uniq(pathParams)) {
app.param(p, (req, res, next, value, name) => {
if (req.openapi.pathParams) {
// override path params
req.params[name] = req.openapi.pathParams[name] || req.params[name];
}
next();
});
}
app.use(middlewares.applyOpenApiMetadata(this.context), middlewares.validateRequest({
apiDoc: this.context.apiDoc,
loggingKey,
enableObjectCoercion: this.opts.enableObjectCoercion,
}));
}
app.use(middlewares.applyOpenApiMetadata(this.context), middlewares.validateRequest({
apiDoc: this.context.apiDoc,
loggingKey,
enableObjectCoercion: this.opts.enableObjectCoercion,
}));
};
}
exports.OpenApiValidator = OpenApiValidator;
//# sourceMappingURL=index.js.map

@@ -45,3 +45,2 @@ "use strict";

const openApiRoute = `${bp}${path}`;
console.log('----', openApiRoute);
const expressRoute = `${openApiRoute}`

@@ -51,3 +50,2 @@ .split('/')

.join('/');
console.log('----', openApiRoute, expressRoute);
routes.push({

@@ -54,0 +52,0 @@ expressRoute,

{
"name": "express-openapi-validator",
"version": "0.21.2",
"version": "0.30.0",
"description": "",

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc