Deprecated
This project was abandonned and is not maintained anymore. For validation, see jsonapi-parser. For deserialization, see jsonapi-deserializable.
jsonapi-validations
Ruby gem for validating JSON API payloads.
Installation
# In Gemfile
gem 'jsonapi-validations'
then
$ bundle
or manually via
$ gem install jsonapi-validations
Usage
First, require the gem:
require 'jsonapi/validations'
Then validate a resource creation/update payload:
params = {
permitted: {
id: true,
attributes: [:name, :address, :birthdate],
relationships: [:posts, :sponsor]
},
required: {
id: true,
attributes: [:name, :address],
relationships: [:sponsor]
},
types: {
primary: [:users, :admins],
relationships: {
posts: {
kind: :has_many,
types: [:blogs, :posts]
}
}
}
}
JSONAPI.validate_resource!(document_hash, params)
or a relationship update payload:
params = {
kind: :has_many,
types: [:users, :admins]
}
JSONAPI.validate_relationship!(document_hash, params)
License
jsonapi-validations is released under the MIT License.