JSONSchema::Validator - Validator for JSON Schema Draft4/Draft6/Draft7 and OpenAPI Specification 3.0
version 0.004
# to get OpenAPI validator of schema in YAML format $validator = JSONSchema::Validator->new(resource => 'file:///some/path/to/oas30.yml'); my ($result, $errors, $warnings) = $validator->validate_request( method => 'GET', openapi_path => '/user/{id}/profile', parameters => { path => { id => 1234 }, query => { details => 'short' }, header => { header => 'header value' }, cookie => { name => 'value' }, body => [$is_exists, $content_type, $data] } ); my ($result, $errors, $warnings) = $validator->validate_response( method => 'GET', openapi_path => '/user/{id}/profile', status => '200', parameters => { header => { header => 'header value' }, body => [$is_exists, $content_type, $data] } ) # to get JSON Schema Draft4/Draft6/Draft7 validator of schema in JSON format $validator = JSONSchema::Validator->new(resource => 'http://example.com/draft4/schema.json') my ($result, $errors) = $validator->validate_schema($object_to_validate)
OpenAPI specification and JSON Schema Draft4/Draft6/Draft7 validators with minimum dependencies.
Creates one of the following validators: JSONSchema::Validator::Draft4, JSONSchema::Validator::Draft6, JSONSchema::Validator::Draft7, JSONSchema::Validator::OAS30.
my $validator = JSONSchema::Validator->new(resource => 'file:///some/path/to/oas30.yml'); my $validator = JSONSchema::Validator->new(resource => 'http://example.com/draft4/schema.json'); my $validator = JSONSchema::Validator->new(schema => {'$schema' => 'path/to/schema', ...}); my $validator = JSONSchema::Validator->new(schema => {...}, specification => 'Draft4');
if parameter specification is not specified then type of validator will be determined by $schema key for JSON Schema Draft4/Draft6/Draft7 and by openapi key for OpenAPI Specification 3.0 in schema parameter.
specification
$schema
openapi
schema
To get schema by uri
To get explicitly specified schema
To specify specification of schema
Do not validate specified schema
To specify base uri of schema. This parameter used to build absolute path by relative reference in schema. By default base_uri is equal to the resource path if the resource parameter is specified otherwise the $id key in the schema.
base_uri
$id
Additional parameters need to be looked at in a specific validator class. Currently there are validators: JSONSchema::Validator::Draft4, JSONSchema::Validator::Draft6, JSONSchema::Validator::Draft7, JSONSchema::Validator::OAS30.
Validate all files specified by path globs.
my $result = JSONSchema::Validator->validate_paths(['/some/path/to/openapi.*.yaml', '/some/path/to/jsonschema.*.json']); for my $file (keys %$result) { my ($res, $errors) = @{$result->{$file}}; }
Alexey Stavrov <logioniz@ya.ru>
Ivan Putintsev <uid@rydlab.ru>
Anton Fedotov <tosha.fedotov.2000@gmail.com>
Denis Ibaev <dionys@gmail.com>
Andrey Khozov <andrey@rydlab.ru>
This software is Copyright (c) 2021 by Alexey Stavrov.
This is free software, licensed under:
The MIT (X11) License
To install JSONSchema::Validator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSONSchema::Validator
CPAN shell
perl -MCPAN -e shell install JSONSchema::Validator
For more information on module installation, please visit the detailed CPAN module installation guide.