JSONSchema-Validator
view release on metacpan or search on metacpan
0.010 2021-12-01
- Added verbosity to test (uid66)
- Fixed bug with $ref and sibling $id
- Added TO_JSON method to Error class (ehuelsmann)
- Fixed bug with wrong detection of booleans
0.009-TRIAL 2021-11-28
- Trial release to find the bug with type boolean
0.008 2021-09-13
- Handle default value of content-type of "encoding" option for body property
0.007 2021-09-11
- Added ability to handle "encoding" option (for now, only decode property by content-type) for body property
0.006 2021-08-07
- Fixed warnings when using undef variables
0.005 2021-08-04
- Fixed bug with dereference undefined value (j-waters)
0.004 2021-08-02
- Added JSON Schema draft7 validator
lib/JSONSchema/Validator/OAS30.pm view on Meta::CPAN
}
sub validate_request {
my ($self, %params) = @_;
my $method = lc($params{method} or croak 'param "method" is required');
my $openapi_path = $params{openapi_path} or croak 'param "openapi_path" is required';
my $get_user_param = $self->_wrap_params($params{parameters});
my $user_body = $params{parameters}{body} // []; # [exists, content-type, value]
my $base_ptr = $self->json_pointer->xget('paths', $openapi_path);
return 1, [], [] unless $base_ptr;
my $schema_params = {query => {}, header => {}, path => {}, cookie => {}};
# Common Parameter Object
my $common_params_ptr = $base_ptr->xget('parameters');
$self->_fill_parameters($schema_params, $common_params_ptr);
lib/JSONSchema/Validator/OAS30.pm view on Meta::CPAN
sub validate_response {
my ($self, %params) = @_;
my $method = lc($params{method} or croak 'param "method" is required');
my $openapi_path = $params{openapi_path} or croak 'param "openapi_path" is required';
my $http_status = $params{status} or croak 'param "status" is required';
my $get_user_param = $self->_wrap_params($params{parameters});
my $user_body = $params{parameters}{body} // []; # [exists, content-type, value]
my $base_ptr = $self->json_pointer->xget('paths', $openapi_path, $method);
return 1, [], [] unless $base_ptr;
my ($result, $context) = (1, {errors => [], warnings => [], direction => 'response'});
if ($base_ptr->xget('deprecated')) {
push @{$context->{warnings}}, error(message => "method $method of $openapi_path is deprecated");
return $result, $context->{errors}, $context->{warnings} unless $self->validate_deprecated;
}
lib/JSONSchema/Validator/OAS30.pm view on Meta::CPAN
my ($self, $ctx, $ptr, $content_type, $data) = @_;
my $content_ptr = $ptr->xget('content');
# content in body is required but in params is optional
return 1, [], [] unless $content_ptr;
my $ctype_ptr;
if ($content_type) {
$ctype_ptr = $content_ptr->xget($content_type);
unless ($ctype_ptr) {
return 0, [error(message => qq{content with content-type $content_type is not in schema})], [];
}
} else {
my $mtype_map = $content_ptr->value;
my @keys = $content_ptr->keys(raw => 1);
return 0, [error(message => qq{content type not specified; schema must have exactly one content_type})], [] unless scalar(@keys) == 1;
$content_type = $keys[0];
$ctype_ptr = $content_ptr->xget($content_type);
}
unless (ref $data) {
if (index($content_type, 'application/json') != -1) {
eval { $data = json_decode($data); };
}
# do we need to support other content-type?
}
my $schema_ptr = $ctype_ptr->xget('schema');
my $schema_prop_ptr = $schema_ptr->xget('properties');
if (
$schema_prop_ptr &&
$content_type &&
(
index($content_type ,'application/x-www-form-urlencoded') != -1 ||
lib/JSONSchema/Validator/OAS30.pm view on Meta::CPAN
if (
index($property_ctype, 'application/json') != -1 &&
exists $data->{$property_name} &&
!ref $data->{$property_name}
) {
eval {
$data->{$property_name} = json_decode($data->{$property_name});
};
}
# do we need to support other content-type?
}
}
return $self->validate_schema($data,
schema => $schema_ptr->value,
path => '/',
direction => $ctx->{direction},
scope => $schema_ptr->scope
);
}
( run in 1.755 second using v1.01-cache-2.11-cpan-d7f47b0818f )