1.0.2 • Published 8 years ago

loopback-jsonapi-model-validator v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

JSONAPI data validator for loopback models

NPM

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

Discover the release history by heading on over to the releases page.

No maintainers yet! Will you be the first?

These amazing people have contributed finances to this project:

Become a sponsor!

These amazing people have contributed code to this project:

Unless stated otherwise all works are:

and licensed under: