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

goodeggs-json-schema-validator

Package Overview
Dependencies
Maintainers
6
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

goodeggs-json-schema-validator

Good Eggs JSON Schema Validator

  • 4.5.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19
decreased by-53.66%
Maintainers
6
Weekly downloads
 
Created
Source

Good Eggs JSON Schema Validator

build status npm version MIT license we're hiring

npm install goodeggs-json-schema-validator
  1. Common JSON schema and tv4 add-ons for Good Eggs ecosystem.
  2. Express middleware to validate requests using JSON Schemas.

Common schema add-ons

Adds support for these formats:

  • objectid
  • date (YYYY-MM-DD)
  • date-time (for example, 2014-05-02T12:59:29+00:00)
  • time (HH:mm or HH:mm:ss, e.g. 23:04:20)
  • email

Simply include the format in your schema:

{"type": "string", "format": "date"}

Express Validation

(Loosely modeled on express-joi-validator.)

When validation fails, uses Boom to wrap errors. Recommended to use Crashpad for passing those errors to the client.

Methods

All methods return middleware that can be use()d or included in a route chain.

  • validateRequest(field, schema, options) validates schema against property on request object
  • validateResponse(field, schema, options) validates schema against property on response object

The schema param should be a JSON Schema, including properties, required, etc. Its type defaults to object.

Example

Validate URL params:

var expressValidator = require('goodeggs-json-schema-validator/lib/express');
var crashpad = require('crashpad')

app.use(crashpad());  // for responding with structured errors

app.get('/products/:slug',
  expressValidator.validateRequest('params', {
    type: 'object'
    properties: {
      'slug': {
        type: 'string'
        pattern: '^[a-z-]+$'
      }
    }
  }),
  function (req, res) {
    // ...
  }
);

If a request is made to /products/INVALID_123, it will fail with statusCode 400 and a body containing message with a description of the error.

Contributing

Please follow our Code of Conduct when contributing to this project.

$ git clone https://github.com/goodeggs/goodeggs-json-schema-validator && cd goodeggs-json-schema-validator
$ npm install
$ npm test

FAQs

Package last updated on 25 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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