-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const express = require('express'); | ||
const schemas = require('../schemas'); | ||
const logger = require('../logger').gateway; | ||
|
||
module.exports = { | ||
name: 'json-schema', | ||
schema: { | ||
$id: 'http://express-gateway.io/schemas/policies/json-schema.json', | ||
type: 'object', | ||
properties: { | ||
schema: { | ||
type: 'object', | ||
description: 'Json schema to validate against.', | ||
examples: ['{"type":"string"}'] | ||
}, | ||
extendedErrors: { | ||
type: 'boolean', | ||
default: false, | ||
description: 'Value istructing the gateway to return the extended Schema Validation errors or a generic Unprocessable Entity' | ||
} | ||
}, | ||
required: ['schema', 'extendedErrors'] | ||
}, | ||
handler: config => { | ||
const validator = schemas.register(String(), String(), config.schema); | ||
return req => { | ||
const { isValid, error } = validator(req.body); | ||
logger.warn(error); | ||
return isValid; | ||
}; | ||
}, | ||
middlewares: [express.json(), express.urlencoded({ extended: false })] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters