Not correctly validating: "The property did not match the following type: string in schema" #101
Closed
Description
Using v2.2.2, I'm unable to get the following to validate correctly:
schema = {
:type => 'object',
:required => %w(anArray),
:properties => {
:anArray => {
:type => 'array',
:items => {
:type => 'object',
:required => %w(aString),
:properties => {
:aString => {
:type => 'string'
}
}
}
}
}
}
data = {
:anArray => [
{
:aString => 'This should validate correctly as a string'
}
]
}
errors = JSON::Validator.fully_validate(schema, data)
The error I get back is this:
"The property '#/anArray/0/aString' of type NilClass did not match the following type: string in schema d3577c07-1a58-5f4d-98ec-f560f6b58001#"
Just to be sure that my schema & data are correct, I can get a JSON version to validate using a tool like this: http://json-schema-validator.herokuapp.com
Here is my JSON schema that I'm using:
{
"type":"object",
"$schema": "http://json-schema.org/draft-03/schema",
"id": "http://jsonschema.net",
"required":false,
"properties":{
"anArray": {
"type":"array",
"id": "http://jsonschema.net/anArray",
"required":true,
"items":
{
"type":"object",
"id": "http://jsonschema.net/anArray/0",
"required":true,
"properties":{
"aString": {
"type":"string",
"id": "http://jsonschema.net/anArray/0/aString",
"required":false
}
}
}
}
}
}
And the data that correctly validates with http://json-schema-validator.herokuapp.com:
{
"anArray": [
{
"aString": "This should validate correctly as a string"
}
]
}
Metadata
Assignees
Labels
No labels