-
-
01 Dec 2021 18:37:03 UTC
- Distribution: JSONSchema-Validator
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers (240 / 0 / 5)
- Kwalitee
Bus factor: 5- 80.73% Coverage
- License: mit
- Perl: v5.16.0
- Activity
24 month- Tools
- Download (49.75KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 8 contributors-
Alexey Stavrov
-
Ivan Putintsev
-
Anton Fedotov
-
Denis Ibaev
-
Andrey Khozov
-
Erik Huelsmann
-
James Waters
-
uid66
NAME
JSONSchema::Validator::OAS30 - Validator for OpenAPI Specification 3.0
VERSION
version 0.010
SYNOPSIS
$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] } );
DESCRIPTION
OpenAPI specification 3.0 validator with minimum dependencies.
CLASS METHODS
new
Creates JSONSchema::Validator::OAS30 object.
$validator = JSONSchema::Validator::OAS30->new(schema => {...});
Parameters
schema
Scheme according to which validation occurs.
strict
Use strong type checks. Default value is 0.
scheme_handlers
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_deprecated
Validate method/parameter/schema with deprecated mark. Default value is 1.
METHODS
validate_request
Validate request specified by method and openapi_path.
Parameters
method
HTTP method of request.
openapi_path
OpenAPI path of request.
Need to specify OpenAPI path, not the real path of request.
parameters
Parameters of request. It is an object that contains the following keys:
query
,path
,header
,cookie
andbody
. Keysquery
,path
,header
,cookie
are hash objects which contains key/value pairs. Keybody
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.# 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
Validate response specified by method, openapi_path and http status code.
Parameters
method
HTTP method of request.
openapi_path
OpenAPI path of request.
Need to specify OpenAPI path, not the real path of request.
status
HTTP response status code.
parameters
Parameters of response. It is an object that contains the following keys:
header
andbody
. Keyheader
are hash objects which contains key/value pairs. Keybody
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'}] } );
AUTHORS
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>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2021 by Alexey Stavrov.
This is free software, licensed under:
The MIT (X11) License
Module Install Instructions
To install JSONSchema::Validator, copy and paste the appropriate command in to your terminal.
cpanm JSONSchema::Validator
perl -MCPAN -e shell install JSONSchema::Validator
For more information on module installation, please visit the detailed CPAN module installation guide.