loopback-jsonapi-model-validator
JSONAPI data validator for loopback models
Install
NPM
- Install:
npm install --save loopback-jsonapi-model-validator
- Module:
require('loopback-jsonapi-model-validator')
Usage
Basic usage
const validate = require('loopback-jsonapi-model-validator')
const data = {id: '1', type: 'posts', attributes: {title: 'My Post'}}
const Post = app.models.Post
const options = {requireId: false}
try {
validate(data, Post, options)
} catch (e) {
// e will contain descriptive validation errors if validation fails
}
Method signature
validate(data, Model, options)
data
JSON API formatted data. The data to be validated as valid JSON API data.
Model
Loopback model. This is used to infer things such as attributes and relationships about the data payload.
options
Additional options, see below.
options
options.requireId
When true, data
will be required to contain a valid id
property. Default: true
options.validatePrimaryKey
When true, primary key will be validated. When false will be ignored. Default: false
options.validateForeignKeys
When true, foreign keys will be validated. When false will be ignored. Default: false
History
Discover the release history by heading on over to the releases page.
Backers
Maintainers
No maintainers yet! Will you be the first?
Sponsors
These amazing people have contributed finances to this project:
Become a sponsor!
Contributors
These amazing people have contributed code to this project:
License
Unless stated otherwise all works are:
- Copyright © Richard Walker
and licensed under: