Hi, guys!
I'm having some troubles to validate some array properties from an object. Probably I've done something wrong!
The HASH that must be validated is:
hash = {
:entitlements => [
{
:id => '111998',
:title => 'Entitlement 1',
:assetId => '000777'
},
{
:id => '111999',
:title => 'Entitlement 2',
:assetId => '000777'
}
],
:offers => [
{
:id => '111001',
:title => 'Offer 1' :price => 100
},
{
:id => '111002',
:title => 'Offer 2'
}
]
}
I'm trying to validate:
- The main object has two properties (entitlements and offers)
- All 'entitlements' objects have their properties (id, title and assetId)
- All 'offers' objects have their properties (id, title and price)
- Price is not mandatory
And this is the schema I tried to use:
options_schema = {
:type => 'object',
:required => %w"offers entitlements",
:properties => {
:entitlements => {
:type => 'array',
:properties => {
:item => {
:type => 'object',
:required => %w"id",
}
}
}
:offers => { :type => 'array',
:properties => {
:item => {
:type => 'object',
:required => %w"id",
}
}
}
}
}
When I run the "JSON::Validator.validate(options_schema, hash)", its always returns TRUE.
How can I validate object arrays on properties?
Thanks!
Thiago de Castro