New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-openapi-validation

Package Overview
Dependencies
Maintainers
2
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-openapi-validation - npm Package Compare versions

Comparing version 0.5.3 to 0.5.4

test/data-driven/accept-recursive-ref-in-body-as-object.js

48

index.js

@@ -26,2 +26,3 @@ var convert = require('openapi-jsonschema-parameters');

var bodySchema = schemas.body;
var bodyValidationSchema;
var headersSchema = lowercasedHeaders(schemas.headers);

@@ -33,2 +34,10 @@ var pathSchema = schemas.path;

if (bodySchema) {
bodyValidationSchema = {
properties: {
body: bodySchema
}
};
}
if (args.schemas) {

@@ -40,16 +49,12 @@ if (Array.isArray(args.schemas)) {

if (id) {
var localSchemaPath;
var localSchemaPath = LOCAL_DEFINITION_REGEX.exec(id);
if (bodySchema) {
localSchemaPath = LOCAL_DEFINITION_REGEX.exec(id);
}
if (localSchemaPath && bodyValidationSchema) {
var definitions = bodyValidationSchema[localSchemaPath[1]];
if (localSchemaPath) {
var localSchemas = bodySchema[localSchemaPath[1]];
if (!localSchemas) {
localSchemas = bodySchema[localSchemaPath[1]] = {};
if (!definitions) {
definitions = bodyValidationSchema[localSchemaPath[1]] = {};
}
localSchemas[localSchemaPath[2]] = schema;
definitions[localSchemaPath[2]] = schema;
}

@@ -63,3 +68,3 @@

} else if (bodySchema) {
bodySchema.definitions = args.schemas;
bodyValidationSchema.definitions = args.schemas;
}

@@ -76,3 +81,3 @@ }

try {
var validation = v.validate(req.body, bodySchema);
var validation = v.validate({body: req.body}, bodyValidationSchema);
errors.push.apply(errors, withAddedLocation('body', validation.errors));

@@ -153,10 +158,23 @@ } catch(e) {

function toOpenapiValidationError(error) {
return {
path: error.property.replace(/^instance\.?/, '') || error.argument,
return stripBodyInfo({
path: error.property.replace(
error.location === 'body' ?
/^instance\.body\.?/ :
/^instance\.?/, '') || error.argument,
errorCode: error.name + '.openapi.validation',
message: error.stack,
location: error.location
};
});
}
function stripBodyInfo(error) {
if (error.location === 'body') {
error.path = error.path.replace(/^body\./, '');
error.message = error.message.replace(/^instance\.body\./, 'instance.');
error.message = error.message.replace(/^instance\.body /, 'instance ');
}
return error;
}
function withAddedLocation(location, errors) {

@@ -163,0 +181,0 @@ if (errors) {

{
"name": "express-openapi-validation",
"version": "0.5.3",
"version": "0.5.4",
"description": "Express middleware for openapi parameter validation.",

@@ -5,0 +5,0 @@ "scripts": {

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