Skip to content

Instantly share code, notes, and snippets.

@pd
Created October 25, 2014 18:25
Show Gist options
  • Save pd/0a6dabe535d0e2ceeb69 to your computer and use it in GitHub Desktop.
Save pd/0a6dabe535d0e2ceeb69 to your computer and use it in GitHub Desktop.
Reproducing hoxworth/json-schema issue #96
# https://github.com/hoxworth/json-schema/issues/96
require 'json-schema'
schema = {
:type => :object,
:required => [
:id,
:name,
:real_name,
:role,
:website,
:biography,
:created_at,
:demographic
],
:properties => {
:id => {
:type => [
:integer
]
},
:name => {
:type => [
:string
]
},
:real_name => {
:type => [
:string
]
},
:role => {
:type => [
:string
]
},
:website => {
:type => [
:string,
:null
]
},
:created_at => {
:type => [
:string
]
},
:biography => {
:type => [
:string,
:null
]
}
},
:relationships => {
:demographic => {
:type => :object,
:required => [
:id,
:gender
],
:properties => {
:id => {
:type => [
:integer
]
},
:gender => {
:type => [
:string
]
}
}
}
}
}
obj = '{
"created_at": "2014-01-25T00:58:33-08:00",
"id": "8c51eebb719a430091a34021ca49003a",
"name": "chelsey",
"real_name": "Mekhi Hegmann",
"website": null,
"role": "user",
"biography": null,
"demographic": null
}'
JSON::Validator.validate!(schema, obj, validate_schema: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment