How to use the express-json-validator-middleware.Validator function in express-json-validator-middleware

To help you get started, we’ve selected a few express-json-validator-middleware examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NYCPlanning / labs-mapboxgl-print-service / routes / config.js View on Github external
const defaultConfig = {
  mapConfig: {
    container: 'map',
    style: '//raw.githubusercontent.com/NYCPlanning/labs-gl-style/master/data/style.json',
    center: [-73.93181409196421, 40.708434183373726],
    zoom: 10.2,
    bearing: 0,
    pitch: 0,
  },
  title: 'New York City',
  logo: 'https://raw.githubusercontent.com/NYCPlanning/logo/master/dcp_logo_772.png',
  content: '',
};

// Initialize a Validator instance first
const validator = new Validator({allErrors: true}); // pass in options to the Ajv instance

// Define a shortcut function
const validate = validator.validate;

// Define a JSON Schema
const PrintSchema = {
  type: 'object',
  required: ['title', 'mapConfig'],
  properties: {
    title: {
      type: 'string',
    },
    mapConfig: {
      type: 'object',
      required: ['style', 'center', 'zoom'],
      properties: {
github decentraland / ethalarm / src / routes / alarms.js View on Github external
import { Validator } from 'express-json-validator-middleware'

import AlarmSchema from '../schemas/alarms'

const validator = new Validator({ allErrors: true })
const validate = validator.validate.bind(validator)

export default class AlarmRouter {
  constructor(alarmService) {
    this.alarm = alarmService
  }

  setup(app) {
    app.post('/alarms', validate({ body: AlarmSchema }), this.postAlarm)
    app.get('/alarms/:id', this.getAlarm)
    app.delete('/alarms/:id', this.deleteAlarm)
  }

  get postAlarm() {
    return (req, res) => buildResponseSchema(this.alarm.storeNewAlarm(req.body), res)
  }

express-json-validator-middleware

An Express middleware to validate requests against JSON Schemas

MIT
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis

Popular express-json-validator-middleware functions