JSONSchema::Validator::OAS30 - Validator for OpenAPI Specification 3.0
version 0.009
$validator = JSONSchema::Validator::OAS30->new(schema => {...}); 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] } );
OpenAPI specification 3.0 validator with minimum dependencies.
Creates JSONSchema::Validator::OAS30 object.
$validator = JSONSchema::Validator::OAS30->new(schema => {...});
Scheme according to which validation occurs.
Use strong type checks. Default value is 0.
At the moment, the validator can load a resource using the http, https protocols. You can add other protocols yourself.
sub loader { my $uri = shift; ... } $validator = JSONSchema::Validator::Draft4->new(schema => {...}, scheme_handlers => {ftp => \&loader});
Validate method/parameter/schema with deprecated mark. Default value is 1.
Validate request specified by method and openapi_path.
HTTP method of request.
OpenAPI path of request.
Need to specify OpenAPI path, not the real path of request.
Parameters of request. It is an object that contains the following keys: query, path, header, cookie and body. Keys query, path, header, cookie are hash objects which contains key/value pairs. Key body is a array reference which contains 3 values. The first value is a boolean flag that means if there is a body. The second value is a Content-Type of request. The third value is a data of value.
query
path
header
cookie
body
# post params my ($result, $errors, $warnings) = $validator->validate_request( method => 'POST', parameters => { path => {user => 'adam'}, body => [1, 'application/x-www-form-urlencoded', {key => 'value'}] } ); # for file upload my ($result, $errors, $warnings) = $validator->validate_request( method => 'POST', parameters => { body => [1, 'multipart/form-data', {key => 'value', file => 'binary data'}] } ); # for multiple file upload for the same name my ($result, $errors, $warnings) = $validator->validate_request( method => 'POST', parameters => { body => [1, 'multipart/form-data', {key => 'value', files => ['binary data1', 'binary data2']}] } );
Validate response specified by method, openapi_path and http status code.
HTTP response status code.
Parameters of response. It is an object that contains the following keys: header and body. Key header are hash objects which contains key/value pairs. Key body is a array reference which contains 3 values. The first value is a boolean flag that means if there is a body. The second value is a Content-Type of response. The third value is a data of value.
# to validate application/json response my ($result, $errors, $warnings) = $validator->validate_response( method => 'GET', openapi_path => '/user/{id}', status => '404', parameters => { header => {name => 'value'}, body => [1, 'application/json', {message => 'user not found'}] } );
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.