No commit activity in last 3 years
No release in over 3 years
Validate presence/absence of resource creation/update and relationship update payloads, as well as types related resources
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0.9
~> 3.4

Runtime

 Project Readme

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.