.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "JSON::Validator::OpenAPI::Mojolicious 3pm" .TH JSON::Validator::OpenAPI::Mojolicious 3pm "2021-01-30" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" JSON::Validator::OpenAPI::Mojolicious \- JSON::Validator request/response adapter for Mojolicious .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& my $validator = JSON::Validator::OpenAPI::Mojolicious\->new; \& $validator\->load_and_validate_schema("myschema.json"); \& \& my @errors = $validator\->validate_request( \& $c, \& $validator\->get([paths => "/wharever", "get"]), \& $c\->validation\->output, \& ); \& \& @errors = $validator\->validate_response( \& $c, \& $validator\->get([paths => "/wharever", "get"]), \& 200, \& {some => {response => "data"}}, \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" JSON::Validator::OpenAPI::Mojolicious is a module for validating request and response data from/to your Mojolicious application. .PP Do not use this module directly. Use Mojolicious::Plugin::OpenAPI instead. .SH "STASH VARIABLES" .IX Header "STASH VARIABLES" .SS "openapi_negotiated_content_type" .IX Subsection "openapi_negotiated_content_type" .Vb 1 \& $str = %c\->stash("openapi_negotiated_content_type"); .Ve .PP This value will be set when the Accept header has been validated successfully against an OpenAPI v3 schema. Note that this could have the value of \*(L"*/*\*(R" or other invalid \*(L"Content-Header\*(R" values. It will be \f(CW\*(C`undef\*(C'\fR if the \*(L"Accept\*(R" header is not accepteed. .PP Unfortunately, this variable is not set until you call \&\*(L"render\*(R" in Mojolicious::Controller, since we need a status code to figure out which types are accepted. .PP This means that if you want to validate the \*(L"Accept\*(R" header on input, then you have to specify that as a parameter in the spec. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" JSON::Validator::OpenAPI::Mojolicious inherits all attributes from JSON::Validator. .SS "formats" .IX Subsection "formats" .Vb 2 \& $validator = $validator\->formats({}); \& $hash_ref = $validator\->formats; .Ve .PP Open \s-1API\s0 support the same formats as JSON::Validator, but adds the following to the set: .IP "\(bu" 4 byte .Sp A padded, base64\-encoded string of bytes, encoded with a \s-1URL\s0 and filename safe alphabet. Defined by \s-1RFC4648.\s0 .IP "\(bu" 4 date .Sp An \s-1RFC3339\s0 date in the format YYYY-MM-DD .IP "\(bu" 4 double .Sp Cannot test double values with higher precision then what the \*(L"number\*(R" type already provides. .IP "\(bu" 4 float .Sp Will always be true if the input is a number, meaning there is no difference between \*(L"float\*(R" and \*(L"double\*(R". Patches are welcome. .IP "\(bu" 4 int32 .Sp A signed 32 bit integer. .IP "\(bu" 4 int64 .Sp A signed 64 bit integer. Note: This check is only available if Perl is compiled to use 64 bit integers. .SS "version" .IX Subsection "version" .Vb 1 \& $str = $validator\->version; .Ve .PP Used to get the OpenAPI Schema version to use. Will be set automatically when using \*(L"load_and_validate_schema\*(R", unless already set. Supported values are \&\*(L"2\*(R" an \*(L"3\*(R". .SH "METHODS" .IX Header "METHODS" JSON::Validator::OpenAPI::Mojolicious inherits all attributes from JSON::Validator. .SS "load_and_validate_schema" .IX Subsection "load_and_validate_schema" .Vb 1 \& $validator = $validator\->load_and_validate_schema($schema, \e%args); .Ve .PP Will load and validate \f(CW$schema\fR against the OpenAPI specification. \f(CW$schema\fR can be anything \*(L"schema\*(R" in JSON::Validator accepts. The expanded specification will be stored in \*(L"schema\*(R" in JSON::Validator on success. See \&\*(L"schema\*(R" in JSON::Validator for the different version of \f(CW$url\fR that can be accepted. .PP \&\f(CW%args\fR can be used to further instruct the expansion and validation process: .IP "\(bu" 2 allow_invalid_ref .Sp 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 \&\f(CW$ref\fR in your specification. .IP "\(bu" 2 version_from_class .Sp Setting this to a module/class name will use the version number from the class and overwrite the version in the specification: .Sp .Vb 5 \& { \& "info": { \& "version": "1.00" // <\-\- this value \& } \& } .Ve .PP The validation is done with a two pass process: .IP "1." 2 First it will check if the \f(CW$ref\fR is only specified on the correct places. This can be disabled by setting \*(L"allow_invalid_ref\*(R" to a true value. .IP "2." 2 Validate the expanded version of the spec, (without any \f(CW$ref\fR) against the OpenAPI schema. .SS "validate_input" .IX Subsection "validate_input" .Vb 1 \& @errors = $validator\->validate_input($data, $schema); .Ve .PP This method will make sure \*(L"readOnly\*(R" is taken into account, when validating data sent to your \s-1API.\s0 .SS "validate_request" .IX Subsection "validate_request" .Vb 1 \& @errors = $validator\->validate_request($c, $schema, \e%input); .Ve .PP Takes an Mojolicious::Controller and a schema definition and returns a list of errors, if any. Validated input parameters are moved into the \f(CW%input\fR hash. .SS "validate_response" .IX Subsection "validate_response" .Vb 1 \& @errors = $validator\->validate_response($c, $schema, $status, $data); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious::Plugin::OpenAPI. .PP JSON::Validator. .PP