JSON-Validator
view release on metacpan or search on metacpan
t/issue-272-recursive-data-protection.t view on Meta::CPAN
components => {
parameters => {
Id => {in => 'path', name => 'id', required => true, schema => {'$ref' => '#/components/schemas/IdType'}},
},
schemas => {IdType => {type => 'integer'}},
},
};
}
my $spec_url = 'https://spec.openapis.org/oas/3.1/schema/2021-05-20';
my $iterations = 500;
my (%errors, $failures);
for (1 .. $iterations) {
my $schema = JSON::Validator::Schema::OpenAPIv3->new(spec(), specification => $spec_url);
next unless my @e = @{$schema->errors};
$failures++;
$errors{"$_"}++ for @e;
}
is $failures, undef, "valid 3.1 \$ref parameter stays valid across $iterations validations (#272)"
or diag "spurious errors: " . join(', ', map {"$_ x$errors{$_}"} sort keys %errors);
done_testing;
t/random-errors.t view on Meta::CPAN
use Mojo::Base -strict;
use JSON::Validator;
use Test::More;
# Note that you might have to run this test many times before it fails:
# while TEST_RANDOM_ITERATIONS=10000 prove -l t/random-errors.t; do echo "---"; done
plan skip_all => 'TEST_RANDOM_ITERATIONS=10000' unless my $iterations = $ENV{TEST_RANDOM_ITERATIONS};
my $jv = JSON::Validator->new->schema({
items => {
properties => {
prop1 => {type => [qw(string null)]},
prop2 => {type => [qw(string null)], format => 'ipv4'},
prop3 => {type => [qw(string null)], format => 'ipv4'},
prop4 => {type => 'string', enum => [qw(foo bar)]},
prop5 => {type => [qw(string null)]},
prop6 => {type => 'string'},
prop7 => {type => 'string', enum => [qw(foo bar)]},
prop8 => {type => [qw(string null)], format => 'ipv4'},
prop9 => {type => [qw(string null)]},
},
type => 'object',
},
type => 'array',
});
my @errors;
for (1 .. $iterations) {
push @errors,
$jv->validate([{
prop1 => undef,
prop2 => undef,
prop3 => undef,
prop4 => 'foo',
prop5 => undef,
prop6 => 'foo',
prop7 => 'bar',
prop8 => undef,
( run in 0.710 second using v1.01-cache-2.11-cpan-5511b514fd6 )