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

express-json-schema-validation

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-json-schema-validation - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

.drone.yml

4

build/validation-error.js

@@ -7,3 +7,3 @@ 'use strict';

class ValidationError extends Error {
constructor(message, errors) {
constructor(pointer, message) {
super();

@@ -14,5 +14,5 @@ Error.captureStackTrace(this, this.constructor);

this.message = message;
this.errors = errors;
this.pointer = pointer;
}
}
exports.default = ValidationError;

@@ -18,5 +18,5 @@ 'use strict';

return schema => (req, res, next) => {
const error = validator.validate(schema, req.body);
if (error) {
return next(error);
const errors = validator.validate(schema, req.body);
if (errors) {
return next(errors);
}

@@ -23,0 +23,0 @@ next();

@@ -21,3 +21,3 @@ 'use strict';

function getErrorMessage(err) {
function getErrorData(err) {
switch (err.keyword) {

@@ -51,2 +51,7 @@ case 'required':

function getError(err) {
err = getErrorData(err);
return new _validationError2.default(err.pointer, err.message);
}
class Validator {

@@ -64,6 +69,5 @@ constructor(schemas) {

const errors = _lodash2.default.map(this.ajv.errors, getErrorMessage);
return new _validationError2.default('Validation error', errors);
return _lodash2.default.map(this.ajv.errors, getError);
}
}
exports.default = Validator;
{
"name": "express-json-schema-validation",
"version": "0.1.2",
"version": "0.1.3",
"description": "Express JSON Schema validation middleware",

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

@@ -41,7 +41,4 @@ # express-json-schema-validation

```
function handleError (err, req, res, next) {
switch(err.code) {
'EVALIDATION':
res.status(422).json(err)
}
function handleErrors (errors, req, res, next) {
res.status(422).json(errors)
}

@@ -53,5 +50,5 @@ ```

const validator = new Validator({ model })
const error = validator.validate('model', object)
if (error) {
// ValidationError
const errors = validator.validate('model', object)
if (errors) {
// ValidationErrors
}

@@ -64,7 +61,5 @@ ```

code: 'EVALIDATION',
errors: [{
pointer: '/id' // invalid property pointer,
message: 'validation error' // validation message
}]
pointer: '/id' // invalid property pointer,
message: 'validation error' // validation message
})
```
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