Skip to content

Commit

Permalink
Merge 36e9dba into bef42d4
Browse files Browse the repository at this point in the history
  • Loading branch information
pokutuna committed Feb 3, 2020
2 parents bef42d4 + 36e9dba commit d944248
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
7 changes: 1 addition & 6 deletions .travis.yml
@@ -1,15 +1,10 @@
language: perl
perl:
- "5.12"
- "5.14"
- "5.16"
- "5.18"
- "5.20"
- "5.22"
- "5.24"
sudo: false

before_install:
- cpanm -n Devel::Cover::Report::Coveralls
after_script:
- cover -test -report coveralls
- cover -test -report coveralls
5 changes: 3 additions & 2 deletions lib/Valiemon/Attributes/Properties.pm
Expand Up @@ -32,8 +32,9 @@ sub is_valid {
$data->{$prop} = clone($default);
# in case default value applied, skip validation for default value
next;
} elsif ($definition->{required}) {
# if required specified and default not exists, it's invalid
} elsif ($context->prims->is_boolean($definition->{required}) && $definition->{required}) {
# if {required: true} specified and default not exists, it's invalid(draftv3).
# if {required: [properties]} specified, just skip it(draftv4).
# TODO check definition. Is it valid existing "default" and "required" in same property???
$is_valid=0;
last;
Expand Down
43 changes: 43 additions & 0 deletions t/02-attr-required.t
Expand Up @@ -48,6 +48,49 @@ subtest 'validate required with object' => sub {
is $error->position, '/required';
};

subtest 'nothing required with object' => sub {
my ($res, $error);
my $v = Valiemon->new({
type => 'object',
properties => {
name => { type => 'string' },
age => { type => 'integer' },
},
});

($res, $error) = $v->validate({});
ok $res;
is $error, undef;
};

subtest 'required with optional object' => sub {
my ($res, $error);
my $v = Valiemon->new({
type => 'object',
properties => {
opt => {
type => 'object',
required => [qw(req)],
properties => {
req => {
type => 'string'
}
}
}
},
});

($res, $error) = $v->validate({});
ok $res;
is $error, undef;
($res, $error) = $v->validate({ opt => {} });
ok ! $res;
ok $error;
($res, $error) = $v->validate({ opt => { req => "foo" } });
ok $res;
is $error, undef;
};

subtest 'detect schema error' => sub {
{
eval {
Expand Down

0 comments on commit d944248

Please sign in to comment.