1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
use lib '.';
use t::Helper;
my $faithful = {
type => 'object',
properties => {constancy => {const => "as the northern star"}}
};
my $ambitious = {
type => 'object',
properties =>
{constancy => {const => "there is a tide in the affairs of men"}}
};
validate_ok {name => "Caesar", constancy => "as the northern star"}, $faithful;
validate_ok {name => "Brutus",
constancy => "there is a tide in the affairs of men"}, $ambitious;
validate_ok {name => "Cassius",
constancy => "Cassius from bondage will deliver Cassius"}, $faithful,
E('/constancy', q{Does not match const: "as the northern star".});
validate_ok(
{
name => "Calpurnia",
constancy =>
"Do not go forth today. Call it my fear That keeps you in the house"
},
$ambitious,
E(
'/constancy',
q{Does not match const: "there is a tide in the affairs of men".}
)
);
# Now oneOf should work right
# before the fix, this failed with: "All of the oneOf rules match."
# because "likes: chocolate" vs. "peanutbutter" wasn't being considered
my $schema = {
type => 'object',
properties => {
people => {
type => 'array',
items => {
oneOf => [
{'$ref' => '#/definitions/chocolate'},
{'$ref' => '#/definitions/peanutbutter'}
],
},
},
},
definitions => {
chocolate => {
type => 'object',
properties => {
name => {type => 'string'},
age => {type => 'number'},
likes => {const => 'chocolate'}
},
},
peanutbutter => {
type => 'object',
properties => {
name => {type => 'string'},
age => {type => 'number'},
likes => {const => 'peanutbutter'},
},
},
},
};
validate_ok {
people => [{name => 'mr. chocolate fan', age => 42, likes => 'peanutbutter'}]
}, $schema;
done_testing;
|