zigorou / perl-JSV

JSON Schema implementation for Perl
Other
25 stars 17 forks source link

Random verification results on enum #50

Open maksym3d opened 7 years ago

maksym3d commented 7 years ago

I seem to get random validation results when validating a valid instance (sometimes the result is '1', sometimes it is '0'). If I remove the 'Palette' attribute - results are always consistent. Further, if I set Palette to invalid value (not present in enum list) - results are also consistently correct (negative). My schema:

{ "title": "My schema", "type": "object", "properties": { "Data": { "type": "object", "properties": { "Label": { "type": "string" }, "Range": { "type": "object", "properties": { "Min": { "type": "number" }, "Max": { "type": "number" } } } } }, "Y Axis": { "type": "object", "properties": { "Label": { "type": "string" }, "Range": { "type": "object", "properties": { "Min": { "type": "number" }, "Max": { "type": "number" } } } } }, "Palette": { "type": "object", "enum": [ { "label": "text1", "legend": "text2" }] } }, "definitions": { "scale": { "type": "string", "enum": ["Linear", "Log"] } } }

My Perl structure to validate: { 'Y Axis' => { 'Range' => { 'Min' => 0.7, 'Max' => 700 }, 'Label' => 'Height (hPa)' }, 'Data' => { 'Label' => 'label 1', 'Range' => { 'Max' => 0.7, 'Min' => 0.5 } }, 'Palette' => { 'label' => "text1", 'legend' => "text2" }

                                      }

Code:

JSV::Validator->load_environments("draft4"); my $validator = JSV::Validator->new(environment => "draft4"); print $validator->validate($schema, $instance) ,"\n";