-
-
12 Sep 2021 21:39:29 UTC
- Distribution: JSONSchema-Validator
- Module version: 0.008
- Source (raw)
- Browse (raw)
- Changes
- How to Contribute
- Repository
- Issues
- Testers (79 / 0 / 5)
- Kwalitee
Bus factor: 5- 81.37% Coverage
- License: mit
- Perl: v5.16.0
- Activity
24 month- Tools
- Download (48.86KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 7 contributors-
Alexey Stavrov
-
Ivan Putintsev
-
Anton Fedotov
-
Denis Ibaev
-
Andrey Khozov
-
James Waters
-
uid66
NAME
JSONSchema::Validator - Validator for JSON Schema Draft4/Draft6/Draft7 and OpenAPI Specification 3.0
VERSION
version 0.008
SYNOPSIS
# to get OpenAPI validator 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 in JSON format $validator = JSONSchema::Validator->new(resource => 'http://example.com/draft4/schema.json') my ($result, $errors) = $validator->validate_schema($object_to_validate)
DESCRIPTION
OpenAPI specification and JSON Schema Draft4/Draft6/Draft7 validators with minimum dependencies.
METHODS
new
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 byopenapi
key for OpenAPI Specification 3.0 inschema
parameter.Parameters
resources
To get schema by uri
schema
To get explicitly specified schema
specification
To specify specification of schema
validate_schema
Do not validate specified schema
base_uri
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.Additional parameters
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_paths
Validates 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}}; }
validate_resource
validate_resource_schema
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>
CONTRIBUTORS
James Waters <james@jcwaters.co.uk>
uid66 <19481514+uid66@users.noreply.github.com>
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.