JSON::Validator::OpenAPI - OpenAPI is both a subset and superset of JSON Schema
JSON::Validator::OpenAPI can validate Open API (also known as "Swagger") requests and responses that is passed through a Mojolicious powered web application.
JSON::Validator::OpenAPI is currently EXPERIMENTAL. Let me know if you are interested in using this class with another framework than Mojolicious.
JSON::Validator::OpenAPI inherits all attributes from JSON::Validator.
Open API support the same formats as JSON::Validator, but adds the following to the set:
byte
A padded, base64-encoded string of bytes, encoded with a URL and filename safe alphabet. Defined by RFC4648.
date
An RFC3339 date in the format YYYY-MM-DD
double
Cannot test double values with higher precision then what the "number" type already provides.
float
Will always be true if the input is a number, meaning there is no difference between "float" and "double". Patches are welcome.
int32
A signed 32 bit integer.
int64
A signed 64 bit integer. Note: This check is only available if Perl is compiled to use 64 bit integers.
$self = $self->load_and_validate_spec($url, \%args);
Will load and validate $url against the OpenAPI specification. The exapnded specification will be stored in "schema" in JSON::Validator on success. See "schema" in JSON::Validator for the different version of $url that can be accepted.
$url
%args can be used to further instruct the expansion and validation process:
%args
allow_invalid_ref
Setting this to a true value, will disable the first pass. This is useful if you don't like the restrictions set by OpenAPI, regarding where you can use $ref in your specification.
$ref
version_from_class
Setting this to a module/class name will use the version number from the class and overwrite the version in the specification:
{ "info": { "version": "1.00" // <-- this value } }
The validation is done with a two pass process:
First it will check if the $ref is only specified on the correct places. This can be disabled by setting "allow_invalid_ref" to a true value.
Validate the expanded version of the spec, (without any $ref) against the OpenAPI schema.
@errors = $self->validate_input($data, $schema);
This method will make sure "readOnly" is taken into account, when validating data sent to your API.
@errors = $self->validate_request($c, $schema, \%input);
Takes an Mojolicious::Controller and a schema definition and returns a list of errors, if any. Validated input parameters are moved into the %input hash.
%input
@errors = $self->validate_response($c, $schema, $status, $data);
Copyright (C) 2014-2015, Jan Henning Thorsen
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Jan Henning Thorsen - jhthorsen@cpan.org
jhthorsen@cpan.org
To install JSON::Validator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSON::Validator
CPAN shell
perl -MCPAN -e shell install JSON::Validator
For more information on module installation, please visit the detailed CPAN module installation guide.