Socket
Socket
Sign inDemoInstall

express-openapi-validator

Package Overview
Dependencies
Maintainers
1
Versions
278
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 5.3.1 to 5.3.2

2

dist/middlewares/openapi.security.d.ts

@@ -1,2 +0,2 @@

import { OpenAPIV3, SecurityHandlers, OpenApiRequestHandler } from '../framework/types';
import { OpenApiRequestHandler, OpenAPIV3, SecurityHandlers } from '../framework/types';
export declare function security(apiDoc: OpenAPIV3.Document, securityHandlers: SecurityHandlers): OpenApiRequestHandler;

@@ -6,2 +6,16 @@ "use strict";

const defaultSecurityHandler = (req, scopes, schema) => true;
function extractErrorsFromResults(results) {
return results.map(result => {
if (Array.isArray(result)) {
return result.map(it => it).filter(it => !it.success);
}
return [result].filter(it => !it.success);
}).flatMap(it => [...it]);
}
function didAllSecurityRequirementsPass(results) {
return results.every(it => it.success);
}
function didOneSchemaPassValidation(results) {
return results.some(result => Array.isArray(result) ? didAllSecurityRequirementsPass(result) : result.success);
}
function security(apiDoc, securityHandlers) {

@@ -33,39 +47,3 @@ return async (req, res, next) => {

// This assumes OR only! i.e. at least one security passed authentication
let firstError = null;
let success = false;
function checkErrorWithOr(res) {
return res.forEach((r) => {
if (r.success) {
success = true;
}
else if (!firstError) {
firstError = r;
}
});
}
function checkErrorsWithAnd(res) {
let allSuccess = false;
res.forEach((r) => {
if (!r.success) {
allSuccess = false;
if (!firstError) {
firstError = r;
}
}
else if (!firstError) {
allSuccess = true;
}
});
if (allSuccess) {
success = true;
}
}
results.forEach((result) => {
if (Array.isArray(result) && result.length > 1) {
checkErrorsWithAnd(result);
}
else {
checkErrorWithOr(result);
}
});
const success = didOneSchemaPassValidation(results);
if (success) {

@@ -75,3 +53,4 @@ next();

else {
throw firstError;
const errors = extractErrorsFromResults(results);
throw errors[0];
}

@@ -78,0 +57,0 @@ }

{
"name": "express-openapi-validator",
"version": "5.3.1",
"version": "5.3.2",
"description": "Automatically validate API requests and responses with OpenAPI 3 and Express.",

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

Sorry, the diff of this file is not supported yet

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