OpenAPI/Client.pm

filter: Statementstmt 94.5% 157 / 166 Branchbran 80.2% 61 / 76 Conditioncond 65.0% 13 / 20 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 93.7% 30 / 32 Podpod 100% 4 / 4 totaltotal 87.0% 269 / 309 CC 65 SCAR 15.9
CC
65
Cov
88%
_coerce_collection_format
10.1
_generate_class
8.2
new
7.0
CRAP 4.9
« Mojolicious/Command/openapi.pm ↑ Summary
1 package OpenAPI::Client;
2 11 ▶use Mojo::EventEmitter -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 9 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use JSON::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Mojo::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Mojo::Promise;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 9 ▶use constant DEBUG => $ENV{OPENAPI_CLIENT_DEBUG} || 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{'OPENAPI_CLIENT_DEBUG'} || 0
l!l
09
MC/DC0%0/1
$ENV{'OPENAPI_CLIENT_DEBUG'} || 0
$ENV{'OPENAPI_CLIENT_DEBUG'}
Truth table50%1/2
A
A= $ENV{'OPENAPI_CLIENT_DEBUG'}
Aresult
11
00
11  
12 9 our $VERSION = '1.07';
13  
14 has base_url => sub {
15 18 ▶ my $self = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
16 18 my $validator = $self->validator;
17 18 ▶ my $url = $validator->can('base_url') ? $validator->base_url->clone : Mojo::URL->new;
Branch: 1 branch
BranchTrueFalseTotal
$validator->can('base_url') ? : 16 2 18
18 18 ▶ $url->scheme('http') unless $url->scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless $url->scheme 4 14 18
19 18 ▶ $url->host('localhost') unless $url->host;
Branch: 1 branch
BranchTrueFalseTotal
unless $url->host 4 14 18
20 18 return $url;
21 9 };
22  
23 23 ▶has ua => sub { Mojo::UserAgent->new };
Subroutine __ANON__: called CC=1 SCAR=0.0
24  
25 sub call {
26 7 ▶ my ($self, $op) = (shift, shift);
Subroutine call: called CC=2 SCAR=6.9
Pod documented
27 7 ▶ my $code = $self->can($op) or Carp::croak('[OpenAPI::Client] No such operationId');
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->can($op) or Carp::croak("[OpenAPI::Client] No such operationId") 1 6 7
28 6 return $self->$code(@_);
29 }
30  
31 sub call_p {
32 2 ▶ my ($self, $op) = (shift, shift);
Subroutine call_p: called CC=2 SCAR=6.9
Pod documented
33 2 ▶ my $code = $self->can("${op}_p") or return Mojo::Promise->reject('[OpenAPI::Client] No such operationId');
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->can("${op}_p") or return "Mojo::Promise"->reject("[OpenAPI::Client] No such operationId") 1 1 2
34 1 return $self->$code(@_);
35 }
36  
37 sub new {
38 24 ▶ my ($parent, $specification) = (shift, shift);
Subroutine new: called CC=7 SCAR=19.5
Pod documented
39 24 ▶ my $attrs = @_ == 1 ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 24 24
40  
41 24 my $class = $parent->_url_to_class($specification);
42 24 ▶ $parent->_generate_class($class, $specification, $attrs) unless $class->isa($parent);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->isa($parent) 10 14 24
43  
44 24 my $self = $class->SUPER::new($attrs);
45 24 ▶ $self->base_url(Mojo::URL->new($self->{base_url})) if $self->{base_url} and !blessed $self->{base_url};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"base_url"} and not builtin::blessed($self->{"base_url"}) 1 23 24
Condition100%3/3
$self->{"base_url"} and not builtin::blessed($self->{"base_url"})
!ll&&!rl&&r
2211
MC/DC100%2/2
$self->{"base_url"} and not builtin::blessed($self->{"base_url"})
$self->{"base_url"} not builtin::blessed($self->{"base_url"})
Truth table100%3/3
A and not(B)
A= $self->{"base_url"}B= not builtin::blessed($self->{"base_url"})
ABresult
0X0
100
111
46 24 ▶ $self->ua->transactor->name('Mojo-OpenAPI (Perl)') unless $self->{ua};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ua"} 23 1 24
47  
48 24 ▶ if (my $app = delete $self->{app}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $app = delete $self->{"app"}) 8 16 24
49 8 $self->base_url->host(undef)->scheme(undef)->port(undef);
50 8 $self->ua->server->app($app);
51 }
52  
53 24 return $self;
54 }
55  
56 0 ▶sub validator { Carp::confess("validator() is not defined for $_[0]") }
Subroutine validator: not called CC=1 SCAR=6.9
Pod documented
57  
58 sub _generate_class {
59 10 ▶ my ($parent, $class, $specification, $attrs) = @_;
Subroutine _generate_class: called CC=8 SCAR=21.0
60  
61 10 my $jv = JSON::Validator->new;
62 10 ▶ $jv->coerce($attrs->{coerce} // 'booleans,numbers,strings');
Condition50%1/2
$attrs->{"coerce"} // "booleans,numbers,strings"
l!l
010
MC/DC0%0/1
$attrs->{"coerce"} // "booleans,numbers,strings"
$attrs->{"coerce"}
Truth table50%1/2
A
A= $attrs->{"coerce"}
Aresult
11
00
63 10 ▶ $jv->store->ua->server->app($attrs->{app}) if $attrs->{app};
Branch: 1 branch
BranchTrueFalseTotal
if $attrs->{"app"} 5 5 10
64  
65 10 my $schema = $jv->schema($specification)->schema;
66 10 ▶ die "Invalid schema: $specification has the following errors:\n", join "\n", @{$schema->errors} if @{$schema->errors};
Branch: 1 branch
BranchTrueFalseTotal
if @{$schema->errors;} 0 10 10
67  
68 8 ▶ eval <<"HERE" or Carp::confess("package $class: $@");
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval "package $class;\nuse Mojo::Base '${parent}';\n1;\n" or Carp::confess("package ${class}: $@") 0 10 10
69 package $class;
70 use Mojo::Base '$parent';
71 1;
72 HERE
73  
74 10 ▶ Mojo::Util::monkey_patch($class => validator => sub {$schema});
Subroutine validator: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
75 10 ▶ return unless $schema->can('routes'); # In case it is not an OpenAPI spec
Branch: 1 branch
BranchTrueFalseTotal
unless $schema->can("routes") 2 8 10
76  
77 8 for my $route ($schema->routes->each) {
78 13 ▶ next unless $route->{operation_id};
Branch: 1 branch
BranchTrueFalseTotal
unless $route->{"operation_id"} 0 13 13
79 13 warn "[$class] Add method $route->{operation_id}() for $route->{method} $route->{path}\n" if DEBUG;
80 13 $class->_generate_method_bnb($route->{operation_id} => $route);
81 13 $class->_generate_method_p("$route->{operation_id}_p" => $route);
82 }
83 }
84  
85 sub _generate_method_bnb {
86 13 ▶ my ($class, $method_name, $route) = @_;
Subroutine _generate_method_bnb: called CC=1 SCAR=0.3
87  
88 Mojo::Util::monkey_patch $class => $method_name => sub {
89 12 ▶ my $cb = ref $_[-1] eq 'CODE' ? pop : undef;
Subroutine __ANON__: called CC=5 SCAR=17.7
Branch: 2 branches
BranchTrueFalseTotal
ref $_[-1] eq 'CODE' ? : 1 11 12
ref $_[-1] eq 'CODE' ? : 0 5 5
90 12 my $self = shift;
91 12 my $tx = $self->_build_tx($route, @_);
92  
93 12 ▶ if ($tx->error) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tx->error) 6 6 12
if ($tx->error) 3 2 5
94 6 ▶ return $tx unless $cb;
Branch: 2 branches
BranchTrueFalseTotal
unless $cb 5 1 6
unless $cb 3 0 3
95 1 ▶ Mojo::IOLoop->next_tick(sub { $self->$cb($tx) });
Subroutine __ANON__: called CC=1 SCAR=0.4
96 1 return $self;
97 }
98  
99 6 ▶ return $self->ua->start($tx) unless $cb;
Branch: 2 branches
BranchTrueFalseTotal
unless $cb 6 0 6
unless $cb 2 0 2
100 0 ▶ $self->ua->start($tx, sub { $self->$cb($_[1]) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 0 return $self;
102 13 };
103 }
104  
105 sub _generate_method_p {
106 13 ▶ my ($class, $method_name, $route) = @_;
Subroutine _generate_method_p: called CC=1 SCAR=0.1
107  
108 Mojo::Util::monkey_patch $class => $method_name => sub {
109 6 ▶ my $self = shift;
Subroutine __ANON__: called CC=5 SCAR=17.0
110 6 my $tx = $self->_build_tx($route, @_);
111  
112 6 ▶ return $self->ua->start_p($tx) unless my $err = $tx->error;
Branch: 1 branch
BranchTrueFalseTotal
unless my $err = $tx->error 5 1 6
113 1 ▶ return Mojo::Promise->new->reject($err->{message}) unless $err->{code};
Branch: 1 branch
BranchTrueFalseTotal
unless $err->{"code"} 0 1 1
114 1 ▶ return Mojo::Promise->new->reject('WebSocket handshake failed') if $tx->req->is_handshake && !$tx->is_websocket;
Branch: 1 branch
BranchTrueFalseTotal
if $tx->req->is_handshake and not $tx->is_websocket 0 1 1
Condition33%1/3
$tx->req->is_handshake and not $tx->is_websocket
!ll&&!rl&&r
100
MC/DC0%0/2
$tx->req->is_handshake and not $tx->is_websocket
$tx->req->is_handshake not $tx->is_websocket
Truth table33%1/3
A and not(B)
A= $tx->req->is_handshakeB= not $tx->is_websocket
ABresult
0X0
100
111
115 1 return Mojo::Promise->new->resolve($tx);
116 13 };
117 }
118  
119 sub _build_tx {
120 23 ▶ my ($self, $route, $params, %content) = @_;
Subroutine _build_tx: called CC=4 SCAR=13.9
121 23 my $v = $self->validator;
122 23 my $url = $self->base_url->clone;
123 23 my ($tx, %headers);
124  
125 23 ▶ push @{$url->path}, map { local $_ = $_; s,\{([-\w]+)\},{$params->{$1}//''},ge; $_ } grep {length} split '/',
Condition100%2/2
$params->{$1} // ""
l!l
46
MC/DC100%1/1
$params->{$1} // ""
$params->{$1}
Truth table100%2/2
A
A= $params->{$1}
Aresult
11
00
126 23 $route->{path};
127  
128 my @errors = $self->validator->validate_request(
129 [@$route{qw(method path)}],
130 {
131 body => sub {
132 8 ▶ my ($name, $param) = @_;
Subroutine __ANON__: called CC=4 SCAR=13.9
133  
134 8 ▶ if (exists $params->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params->{$name}) { } 4 4 8
135 4 $content{json} = $params->{$name};
136 }
137 else {
138 4 for ('body', sort keys %{$self->ua->transactor->generators}) {
139 14 ▶ next unless exists $content{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $content{$_} 12 2 14
140 2 $params->{$name} = $content{$_};
141 2 last;
142 }
143 }
144  
145 8 return {exists => $params->{$name}, value => $params->{$name}};
146 },
147 formData => sub {
148 8 ▶ my ($name, $param) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
149 8 my $value = _param_as_array($name => $params);
150 8 $content{form}{$name} = $params->{$name};
151 8 return {exists => !!@$value, value => $value};
152 },
153 header => sub {
154 2 ▶ my ($name, $param) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
155 2 my $value = _param_as_array($name => $params);
156 2 $headers{$name} = $value;
157 2 return {exists => !!@$value, value => $value};
158 },
159 path => sub {
160 10 ▶ my ($name, $param) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
161 10 return {exists => exists $params->{$name}, value => $params->{$name}};
162 },
163 query => sub {
164 18 ▶ my ($name, $param) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
165 18 my $value = _param_as_array($name => $params);
166 18 $url->query->param($name => _coerce_collection_format($value, $param));
167 18 return {exists => !!@$value, value => $value};
168 },
169 }
170 23 );
171  
172 23 ▶ if (@errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@errors) { } 10 13 23
173 10 warn "[@{[ref $self]}] Validation for $route->{method} $url failed: @errors\n" if DEBUG;
174 10 $tx = Mojo::Transaction::HTTP->new;
175 10 $tx->req->method(uc $route->{method});
176 10 $tx->req->url($url);
177 10 $tx->res->headers->content_type('application/json');
178 10 $tx->res->body(Mojo::JSON::encode_json({errors => \@errors}));
179 10 $tx->res->code(400)->message($tx->res->default_message);
180 10 $tx->res->error({message => 'Invalid input', code => 400});
181 }
182 else {
183 13 warn "[@{[ref $self]}] Validation for $route->{method} $url was successful\n" if DEBUG;
184 13 ▶ $tx = $self->ua->build_tx($route->{method}, $url, \%headers, defined $content{body} ? $content{body} : %content);
Branch: 1 branch
BranchTrueFalseTotal
defined $content{'body'} ? : 0 13 13
185 }
186  
187 23 $tx->req->env->{operationId} = $route->{operation_id};
188 23 $self->emit(after_build_tx => $tx);
189  
190 23 return $tx;
191 }
192  
193 sub _coerce_collection_format {
194 18 ▶ my ($value, $param) = @_;
Subroutine _coerce_collection_format: called CC=9 SCAR=23.1
195 18 ▶ my $format = $param->{collectionFormat} || (+($param->{type} // '') eq 'array' ? 'csv' : '');
Branch: 1 branch
BranchTrueFalseTotal
($param->{'type'} // '') eq 'array' ? : 1 17 18
Condition60%3/5
$param->{'collectionFormat'} || (($param->{'type'} // '') eq 'array' ? 'csv' : '')
l!l&&r!l&&!r
0117
$param->{"type"} // ""
l!l
180
MC/DC0%0/2
$param->{'collectionFormat'} || (($param->{'type'} // '') eq 'array' ? 'csv' : '')
$param->{'collectionFormat'} $param->{"type"}
Truth table33%1/3
A || B
A= $param->{'collectionFormat'}B= $param->{"type"}
ABresult
1X1
011
000
196 18 ▶ return $value if !$format or $format eq 'multi';
Branch: 1 branch
BranchTrueFalseTotal
if not $format or $format eq "multi" 17 1 18
Condition66%2/3
not $format or $format eq "multi"
l!l&&r!l&&!r
1701
MC/DC50%1/2
not $format or $format eq "multi"
not $format $format eq "multi"
Truth table66%2/3
not(A) or B
A= not $formatB= $format eq "multi"
ABresult
1X1
011
000
197 1 ▶ return join "|", @$value if $format eq 'pipes';
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "pipes" 0 1 1
198 1 ▶ return join " ", @$value if $format eq 'ssv';
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "ssv" 0 1 1
199 1 ▶ return join "\t", @$value if $format eq 'tsv';
Branch: 1 branch
BranchTrueFalseTotal
if $format eq "tsv" 0 1 1
200 1 return join ",", @$value;
201 }
202  
203 sub _param_as_array {
204 28 ▶ my ($name, $params) = @_;
Subroutine _param_as_array: called CC=3 SCAR=11.0
205 28 ▶ return !exists $params->{$name} ? [] : ref $params->{$name} eq 'ARRAY' ? $params->{$name} : [$params->{$name}];
Branch: 2 branches
BranchTrueFalseTotal
!exists $params->{$name} ? : 17 11 28
ref $params->{$name} eq 'ARRAY' ? : 1 10 11
206 }
207  
208 sub _url_to_class {
209 24 ▶ my ($self, $package) = @_;
Subroutine _url_to_class: called CC=2 SCAR=7.0
210  
211 24 $package =~ s!^\w+?://!!;
212 24 $package =~ s!\W!_!g;
213 24 ▶ $package = Mojo::Util::md5_sum($package) if length $package > 110; # 110 is a bit random, but it cannot be too long
Branch: 1 branch
BranchTrueFalseTotal
if length $package > 110 0 24 24
214  
215 24 return "$self\::$package";
216 }
217  
218 9 1;
219  
220 =encoding utf8
221  
222 =head1 NAME
223  
224 OpenAPI::Client - A client for talking to an Open API powered server
225  
226 =head1 DESCRIPTION
227  
228 L<OpenAPI::Client> can generating classes that can talk to an Open API server.
229 This is done by generating a custom class, based on a Open API specification,
230 with methods that transform parameters into a HTTP request.
231  
232 The generated class will perform input validation, so invalid data won't be
233 sent to the server.
234  
235 Note that this implementation is currently EXPERIMENTAL, but unlikely to change!
236 Feedback is appreciated.
237  
238 =head1 SYNOPSIS
239  
240 =head2 Open API specification
241  
242 The specification given to L</new> need to point to a valid OpenAPI document.
243 This document can be OpenAPI v2.x or v3.x, and it can be in either JSON or YAML
244 format. Example:
245  
246 openapi: 3.0.1
247 info:
248 title: Swagger Petstore
249 version: 1.0.0
250 servers:
251 - url: http://petstore.swagger.io/v1
252 paths:
253 /pets:
254 get:
255 operationId: listPets
256 ...
257  
258 C<host>, C<basePath> and the first item in C<schemes> will be used to construct
259 L</base_url>. This can be altered at any time, if you need to send data to a
260 custom endpoint.
261  
262 =head2 Client
263  
264 The OpenAPI API specification will be used to generate a sub-class of
265 L<OpenAPI::Client> where the "operationId", inside of each path definition, is
266 used to generate methods:
267  
268 use OpenAPI::Client;
269 $client = OpenAPI::Client->new("file:///path/to/api.json");
270  
271 # Blocking
272 $tx = $client->listPets;
273  
274 # Non-blocking
275 $client = $client->listPets(sub { my ($client, $tx) = @_; });
276  
277 # Promises
278 $promise = $client->listPets_p->then(sub { my $tx = shift });
279  
280 # With parameters
281 $tx = $client->listPets({limit => 10});
282  
283 See L<Mojo::Transaction> for more information about what you can do with the
284 C<$tx> object, but you often just want something like this:
285  
286 # Check for errors
287 die $tx->error->{message} if $tx->error;
288  
289 # Extract data from the JSON responses
290 say $tx->res->json->{pets}[0]{name};
291  
292 Check out L<Mojo::Transaction/error>, L<Mojo::Transaction/req> and
293 L<Mojo::Transaction/res> for some of the most used methods in that class.
294  
295 =head1 CUSTOMIZATION
296  
297 =head2 Custom server URL
298  
299 If you want to request a different server than what is specified in the Open
300 API document, you can change the L</base_url>:
301  
302 # Pass on a Mojo::URL object to the constructor
303 $base_url = Mojo::URL->new("http://example.com");
304 $client1 = OpenAPI::Client->new("file:///path/to/api.json", base_url => $base_url);
305  
306 # A plain string will be converted to a Mojo::URL object
307 $client2 = OpenAPI::Client->new("file:///path/to/api.json", base_url => "http://example.com");
308  
309 # Change the base_url after the client has been created
310 $client3 = OpenAPI::Client->new("file:///path/to/api.json");
311 $client3->base_url->host("other.example.com");
312  
313 =head2 Custom content
314  
315 You can send XML or any format you like, but this require you to add a new
316 "generator":
317  
318 use Your::XML::Library "to_xml";
319 $client->ua->transactor->add_generator(xml => sub {
320 my ($t, $tx, $data) = @_;
321 $tx->req->body(to_xml $data);
322 return $tx;
323 });
324  
325 $client->addHero({}, xml => {name => "Supergirl"});
326  
327 See L<Mojo::UserAgent::Transactor> for more details.
328  
329 =head1 EVENTS
330  
331 =head2 after_build_tx
332  
333 $client->on(after_build_tx => sub { my ($client, $tx) = @_ })
334  
335 This event is emitted after a L<Mojo::UserAgent::Transactor> object has been
336 built, just before it is passed on to the L</ua>. Note that all validation has
337 already been run, so alternating the C<$tx> too much, might cause an invalid
338 request on the server side.
339  
340 A special L<Mojo::Message::Request/env> variable will be set, to reference the
341 operationId:
342  
343 $tx->req->env->{operationId};
344  
345 Note that this usage of C<env()> is currently EXPERIMENTAL:
346  
347 =head1 ATTRIBUTES
348  
349 =head2 base_url
350  
351 $base_url = $client->base_url;
352  
353 Returns a L<Mojo::URL> object with the base URL to the API. The default value
354 comes from C<schemes>, C<basePath> and C<host> in the OpenAPI v2 specification
355 or from C<servers> in the OpenAPI v3 specification.
356  
357 =head2 ua
358  
359 $ua = $client->ua;
360  
361 Returns a L<Mojo::UserAgent> object which is used to execute requests.
362  
363 =head1 METHODS
364  
365 =head2 call
366  
367 $tx = $client->call($operationId => \%params, %content);
368 $client = $client->call($operationId => \%params, %content, sub { my ($client, $tx) = @_; });
369  
370 Used to either call an C<$operationId> that has an "invalid name", such as
371 "list pets" instead of "listPets" or to call an C<$operationId> that you are
372 unsure is supported yet. If it is not, an exception will be thrown,
373 matching text "No such operationId".
374  
375 C<$operationId> is the name of the resource defined in the
376 L<OpenAPI specification|https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#operation-object>.
377  
378 C<$params> is optional, but must be a hash ref, where the keys should match a
379 named parameter in the L<OpenAPI specification|https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameter-object>.
380  
381 C<%content> is used for the body of the request, where the key need to be
382 either "body" or a matching L<Mojo::UserAgent::Transactor/generators>. Example:
383  
384 $client->addHero({}, body => "Some data");
385 $client->addHero({}, json => {name => "Supergirl"});
386  
387 C<$tx> is a L<Mojo::Transaction> object.
388  
389 =head2 call_p
390  
391 $promise = $client->call_p($operationId => $params, %content);
392 $promise->then(sub { my $tx = shift });
393  
394 As L</call> above, but returns a L<Mojo::Promise> object.
395  
396 =head2 new
397  
398 $client = OpenAPI::Client->new($specification, \%attributes);
399 $client = OpenAPI::Client->new($specification, %attributes);
400  
401 Returns an object of a generated class, with methods generated from the Open
402 API specification located at C<$specification>. See L<JSON::Validator/schema>
403 for valid versions of C<$specification>.
404  
405 Note that the class is cached by perl, so loading a new specification from the
406 same URL will not generate a new class.
407  
408 Extra C<%attributes>:
409  
410 =over 2
411  
412 =item * app
413  
414 Specifying an C<app> is useful when running against a local L<Mojolicious>
415 instance.
416  
417 =item * coerce
418  
419 See L<JSON::Validator/coerce>. Default to "booleans,numbers,strings".
420  
421 =back
422  
423 =head2 validator
424  
425 $validator = $client->validator;
426 $validator = $class->validator;
427  
428 Returns a L<JSON::Validator::Schema::OpenAPIv2> object for a generated class.
429 Note that this is a global variable, so changing the object will affect all
430 instances returned by L</new>.
431  
432 =head1 COPYRIGHT AND LICENSE
433  
434 Copyright (C) 2017-2021, Jan Henning Thorsen
435  
436 This program is free software, you can redistribute it and/or modify it under
437 the terms of the Artistic License version 2.0.
438  
439 =head1 AUTHORS
440  
441 =head2 Project Founder
442  
443 Jan Henning Thorsen - C<jhthorsen@cpan.org>
444  
445 =head2 Contributors
446  
447 =over 2
448  
449  
450 =item * Clive Holloway <clhollow@estee.com>
451  
452 =item * Ed J <mohawk2@users.noreply.github.com>
453  
454 =item * Jan Henning Thorsen <jan.henning@thorsen.pm>
455  
456 =item * Jan Henning Thorsen <jhthorsen@cpan.org>
457  
458 =item * Mohammad S Anwar <mohammad.anwar@yahoo.com>
459  
460 =item * Reneeb <info@perl-services.de>
461  
462 =item * Roy Storey <kiwiroy@users.noreply.github.com>
463  
464 =item * Veesh Goldman <rabbiveesh@gmail.com>
465  
466 =back
467  
468 =cut
« Mojolicious/Command/openapi.pm ↑ Summary