Skip to content

Commit

Permalink
Add failing test when "nick" is part of the enum list
Browse files Browse the repository at this point in the history
  not ok 8 - errors: /name: anyOf failed: Expected string, got null. /name: Not in enum list: supergirl, batboy.
  #   Failed test 'errors: /name: anyOf failed: Expected string, got null. /name: Not in enum list: supergirl, batboy.'
  #   at t/Helper.pm line 24.
  #     Structures begin differing at:
  #          $got->[1] = Does not exist
  #     $expected->[1] = HASH(0x7fda66e80d80)
  # [{"message":"anyOf failed: Expected string, got null.","path":"\/name"}]
  ok 9 - errors: /name: anyOf failed: Expected string, got null. /name: Not in enum list: supergirl, batboy.
  • Loading branch information
Jan Henning Thorsen committed Jan 16, 2018
1 parent 7c79400 commit 81ac60d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/JSON/Validator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ sub _validate {
}
if ($schema->{enum}) {
@errors = $self->_validate_type_enum($data, $path, $schema);
push @errors, $self->_validate_type_enum($data, $path, $schema);
$self->_report_errors($path, 'enum', \@errors) if REPORT;
return @errors if @errors;
}
Expand Down
24 changes: 24 additions & 0 deletions t/jv-enum.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,28 @@ validate_ok(
E('/some_prop/0', 'Not in enum list: x, y.')
);

# This fails, because the "enum" contains the string "nick"!
validate_ok(
{name => undef},
{
type => 'object',
required => ['name'],
properties => {name => {type => ['string'], enum => [qw(alex nick)]}},
},
E('/name', 'anyOf failed: Expected string, got null.'),
E('/name', 'Not in enum list: supergirl, batboy.'),
);

# ...while this is ok
validate_ok(
{name => undef},
{
type => 'object',
required => ['name'],
properties => {name => {type => ['string'], enum => [qw(supergirl batboy)]}},
},
E('/name', 'anyOf failed: Expected string, got null.'),
E('/name', 'Not in enum list: supergirl, batboy.'),
);

done_testing;

0 comments on commit 81ac60d

Please sign in to comment.