serene-conformation
v0.5.0
Published
A validation middleware for Serene using the Conformation library
Downloads
4
Maintainers
Readme
serene-conformation
Validation middleware for Serene, using Conformation.
Example
import Schema from 'conformation';
import Serene from 'serene';
import SereneConformation from 'serene-conformation';
import SereneResources from 'serene-resources';
let service = new Serene();
let resources = {
widgets: {
schema: Schema.object().keys({
name: Schema.string().required(),
description: Schema.string()
})
}
};
// this package depends on SereneResources, which must be registered first
serene.use(new SereneResources(resources));
serene.use(new SereneConformation());
serene.use(function (request, response) {
// this only runs if the request is valid
});
The middleware only validates requests with a body, that is:
- create
- update
- replace
It wraps the schema
found in the resource definition with a attributes
field, so that it
conforms to the SuperAPI spec, and automatically unwraps
the request payload from the attributes
field.
See tests for more details.