Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danmcclain/voorhees
https://github.com/danmcclain/voorhees
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/danmcclain/voorhees
- Owner: danmcclain
- License: mit
- Archived: true
- Created: 2015-04-29T15:10:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-04-03T23:15:12.000Z (almost 9 years ago)
- Last Synced: 2024-10-01T11:08:13.870Z (3 months ago)
- Language: Elixir
- Size: 57.6 KB
- Stars: 42
- Watchers: 2
- Forks: 10
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - A library for validating JSON responses. (Validations)
- fucking-awesome-elixir - voorhees - A library for validating JSON responses. (Validations)
- awesome-elixir - voorhees - A library for validating JSON responses. (Validations)
README
Voorhees
========[![Build Status](https://travis-ci.org/danmcclain/voorhees.svg?branch=master)](https://travis-ci.org/danmcclain/voorhees)
[![Inline docs](http://inch-ci.org/github/danmcclain/voorhees.svg?branch=master)](http://inch-ci.org/github/danmcclain/voorhees)A library for validating JSON responses
## Documentation
API documentation can be found at [http://hexdocs.pm/voorhees](http://hexdocs.pm/voorhees)
## Examples
### `Voorhees.matches_payload?`
Expected payload keys can be either strings or atoms
iex> payload = ~S[{ "foo": 1, "bar": "baz" }]
iex> Voorhees.matches_payload?(payload, %{ :foo => 1, "bar" => "baz" })
trueExtra key/value pairs in payload are ignored
iex> payload = ~S[{ "foo": 1, "bar": "baz", "boo": 3 }]
iex> Voorhees.matches_payload?(payload, %{ :foo => 1, "bar" => "baz" })
trueExtra key/value pairs in expected payload cause the validation to fail
iex> payload = ~S[{ "foo": 1, "bar": "baz"}]
iex> Voorhees.matches_payload?(payload, %{ :foo => 1, "bar" => "baz", :boo => 3 })
falseValidates scalar lists
iex> payload = ~S/{ "foo": 1, "bar": ["baz"]}/
iex> Voorhees.matches_payload?(payload, %{ :foo => 1, "bar" => ["baz"] })
true# Order is respected
iex> payload = ~S/{ "foo": 1, "bar": [1, "baz"]}/
iex> Voorhees.matches_payload?(payload, %{ :foo => 1, "bar" => ["baz", 1] })
falseValidates lists of objects
iex> payload = ~S/[{ "foo": 1, "bar": { "baz": 2 }}]/
iex> Voorhees.matches_payload?(payload, [%{ :foo => 1, "bar" => %{ "baz" => 2 } }])
trueValidates nested objects
iex> payload = ~S/{ "foo": 1, "bar": { "baz": 2 }}/
iex> Voorhees.matches_payload?(payload, %{ :foo => 1, "bar" => %{ "baz" => 2 } })
trueValidates nested lists of objects
iex> payload = ~S/{ "foo": 1, "bar": [{ "baz": 2 }]}/
iex> Voorhees.matches_payload?(payload, %{ :foo => 1, "bar" => [%{ "baz" => 2 }] })
true### `Voorhees.matches_schema?`
Validating simple objects
iex> payload = ~S[{ "foo": 1, "bar": "baz" }]
iex> Voorhees.matches_schema?(payload, [:foo, "bar"]) # Property names can be strings or atoms
true# Extra keys
iex> payload = ~S[{ "foo": 1, "bar": "baz", "boo": 3 }]
iex> Voorhees.matches_schema?(payload, [:foo, "bar"])
false# Missing keys
iex> payload = ~S[{ "foo": 1 }]
iex> Voorhees.matches_schema?(payload, [:foo, "bar"])
falseValidating lists of objects
iex> payload = ~S/[{ "foo": 1, "bar": "baz" },{ "foo": 2, "bar": "baz" }]/
iex> Voorhees.matches_schema?(payload, [:foo, "bar"])
trueValidating nested lists of objects
iex> payload = ~S/{ "foo": 1, "bar": [{ "baz": 2 }]}/
iex> Voorhees.matches_schema?(payload, [:foo, bar: [:baz]])
trueValidating that a property is a list of scalar values
iex> payload = ~S/{ "foo": 1, "bar": ["baz", 2]}/
iex> Voorhees.matches_schema?(payload, [:foo, bar: []])
true