1JSON::Validator::OpenAPUIs:e:rMoCjoonltirciibouutse(d3J)PSeOrNl::DVoacluimdeanttoart:i:oOnpenAPI::Mojolicious(3)
2
3
4

NAME

6       JSON::Validator::OpenAPI::Mojolicious - JSON::Validator
7       request/response adapter for Mojolicious
8

SYNOPSIS

10         my $validator = JSON::Validator::OpenAPI::Mojolicious->new;
11         $validator->load_and_validate_schema("myschema.json");
12
13         my @errors = $validator->validate_request(
14                        $c,
15                        $validator->get([paths => "/wharever", "get"]),
16                        $c->validation->output,
17                      );
18
19         @errors = $validator->validate_response(
20                     $c,
21                     $validator->get([paths => "/wharever", "get"]),
22                     200,
23                     {some => {response => "data"}},
24                   );
25

DESCRIPTION

27       JSON::Validator::OpenAPI::Mojolicious is a module for validating
28       request and response data from/to your Mojolicious application.
29
30       Do not use this module directly. Use Mojolicious::Plugin::OpenAPI
31       instead.
32

STASH VARIABLES

34   openapi_negotiated_content_type
35         $str = %c->stash("openapi_negotiated_content_type");
36
37       This value will be set when the Accept header has been validated
38       successfully against an OpenAPI v3 schema. Note that this could have
39       the value of "*/*" or other invalid "Content-Header" values. It will be
40       "undef" if the "Accept" header is not accepteed.
41
42       Unfortunately, this variable is not set until you call "render" in
43       Mojolicious::Controller, since we need a status code to figure out
44       which types are accepted.
45
46       This means that if you want to validate the "Accept" header on input,
47       then you have to specify that as a parameter in the spec.
48

ATTRIBUTES

50       JSON::Validator::OpenAPI::Mojolicious inherits all attributes from
51       JSON::Validator.
52
53   formats
54         $validator = $validator->formats({});
55         $hash_ref = $validator->formats;
56
57       Open API support the same formats as JSON::Validator, but adds the
58       following to the set:
59
60       ·   byte
61
62           A padded, base64-encoded string of bytes, encoded with a URL and
63           filename safe alphabet. Defined by RFC4648.
64
65       ·   date
66
67           An RFC3339 date in the format YYYY-MM-DD
68
69       ·   double
70
71           Cannot test double values with higher precision then what the
72           "number" type already provides.
73
74       ·   float
75
76           Will always be true if the input is a number, meaning there is no
77           difference between  "float" and "double". Patches are welcome.
78
79       ·   int32
80
81           A signed 32 bit integer.
82
83       ·   int64
84
85           A signed 64 bit integer. Note: This check is only available if Perl
86           is compiled to use 64 bit integers.
87
88   version
89         $str = $validator->version;
90
91       Used to get the OpenAPI Schema version to use. Will be set
92       automatically when using "load_and_validate_schema", unless already
93       set. Supported values are "2" an "3".
94

METHODS

96       JSON::Validator::OpenAPI::Mojolicious inherits all attributes from
97       JSON::Validator.
98
99   load_and_validate_schema
100         $validator = $validator->load_and_validate_schema($schema, \%args);
101
102       Will load and validate $schema against the OpenAPI specification.
103       $schema can be anything "schema" in JSON::Validator accepts. The
104       expanded specification will be stored in "schema" in JSON::Validator on
105       success. See "schema" in JSON::Validator for the different version of
106       $url that can be accepted.
107
108       %args can be used to further instruct the expansion and validation
109       process:
110
111       · allow_invalid_ref
112
113         Setting this to a true value, will disable the first pass. This is
114         useful if you don't like the restrictions set by OpenAPI, regarding
115         where you can use $ref in your specification.
116
117       · version_from_class
118
119         Setting this to a module/class name will use the version number from
120         the class and overwrite the version in the specification:
121
122           {
123             "info": {
124               "version": "1.00" // <-- this value
125             }
126           }
127
128       The validation is done with a two pass process:
129
130       1.
131         First it will check if the $ref is only specified on the correct
132         places.  This can be disabled by setting "allow_invalid_ref" to a
133         true value.
134
135       2.
136         Validate the expanded version of the spec, (without any $ref) against
137         the OpenAPI schema.
138
139   validate_input
140         @errors = $validator->validate_input($data, $schema);
141
142       This method will make sure "readOnly" is taken into account, when
143       validating data sent to your API.
144
145   validate_request
146         @errors = $validator->validate_request($c, $schema, \%input);
147
148       Takes an Mojolicious::Controller and a schema definition and returns a
149       list of errors, if any. Validated input parameters are moved into the
150       %input hash.
151
152   validate_response
153         @errors = $validator->validate_response($c, $schema, $status, $data);
154

SEE ALSO

156       Mojolicious::Plugin::OpenAPI.
157
158       JSON::Validator.
159
160       <http://openapi-specification-visual-documentation.apihandyman.io/>
161
162
163
164perl v5.32.0                      2020-J0S8O-N0:9:Validator::OpenAPI::Mojolicious(3)
Impressum