Lines 21-26
use Mojo::Base 'Mojolicious';
Link Here
|
21 |
|
21 |
|
22 |
use C4::Context; |
22 |
use C4::Context; |
23 |
use JSON::Validator::OpenAPI::Mojolicious; |
23 |
use JSON::Validator::OpenAPI::Mojolicious; |
|
|
24 |
use Try::Tiny; |
24 |
|
25 |
|
25 |
=head1 NAME |
26 |
=head1 NAME |
26 |
|
27 |
|
Lines 58-90
sub startup {
Link Here
|
58 |
} |
59 |
} |
59 |
|
60 |
|
60 |
my $validator = JSON::Validator::OpenAPI::Mojolicious->new; |
61 |
my $validator = JSON::Validator::OpenAPI::Mojolicious->new; |
61 |
$validator->load_and_validate_schema( |
|
|
62 |
$self->home->rel_file("api/v1/swagger/swagger.json"), |
63 |
{ |
64 |
allow_invalid_ref => 1, |
65 |
} |
66 |
); |
67 |
|
62 |
|
68 |
push @{$self->routes->namespaces}, 'Koha::Plugin'; |
63 |
push @{$self->routes->namespaces}, 'Koha::Plugin'; |
69 |
|
64 |
|
70 |
my $spec = $validator->schema->data; |
65 |
# Try to load and merge all schemas first and validate the result just once. |
71 |
$self->plugin( |
66 |
my $spec; |
72 |
'Koha::REST::Plugin::PluginRoutes' => { |
67 |
try { |
73 |
spec => $spec, |
68 |
$spec = $validator->bundle( |
74 |
validator => $validator |
69 |
{ |
75 |
} |
70 |
replace => 1, |
76 |
); |
71 |
schema => $self->home->rel_file("api/v1/swagger/swagger.json") |
77 |
|
72 |
} |
78 |
$self->plugin( |
73 |
); |
79 |
OpenAPI => { |
74 |
|
80 |
spec => $spec, |
75 |
$self->plugin( |
81 |
route => $self->routes->under('/api/v1')->to('Auth#under'), |
76 |
'Koha::REST::Plugin::PluginRoutes' => { |
82 |
allow_invalid_ref => |
77 |
spec => $spec, |
83 |
1, # required by our spec because $ref directly under |
78 |
validator => undef |
84 |
# Paths-, Parameters-, Definitions- & Info-object |
79 |
} |
85 |
# is not allowed by the OpenAPI specification. |
80 |
); |
86 |
} |
81 |
|
87 |
); |
82 |
$self->plugin( |
|
|
83 |
OpenAPI => { |
84 |
spec => $spec, |
85 |
route => $self->routes->under('/api/v1')->to('Auth#under'), |
86 |
allow_invalid_ref => |
87 |
1, # required by our spec because $ref directly under |
88 |
# Paths-, Parameters-, Definitions- & Info-object |
89 |
# is not allowed by the OpenAPI specification. |
90 |
} |
91 |
); |
92 |
} |
93 |
catch { |
94 |
# Validation of the complete spec failed. Resort to validation one-by-one |
95 |
# to catch bad ones. |
96 |
$validator->load_and_validate_schema( |
97 |
$self->home->rel_file("api/v1/swagger/swagger.json"), |
98 |
{ |
99 |
allow_invalid_ref => 1, |
100 |
} |
101 |
); |
102 |
|
103 |
$spec = $validator->schema->data; |
104 |
$self->plugin( |
105 |
'Koha::REST::Plugin::PluginRoutes' => { |
106 |
spec => $spec, |
107 |
validator => $validator |
108 |
} |
109 |
); |
110 |
|
111 |
$self->plugin( |
112 |
OpenAPI => { |
113 |
spec => $spec, |
114 |
route => $self->routes->under('/api/v1')->to('Auth#under'), |
115 |
allow_invalid_ref => |
116 |
1, # required by our spec because $ref directly under |
117 |
# Paths-, Parameters-, Definitions- & Info-object |
118 |
# is not allowed by the OpenAPI specification. |
119 |
} |
120 |
); |
121 |
}; |
88 |
|
122 |
|
89 |
$self->plugin( 'Koha::REST::Plugin::Pagination' ); |
123 |
$self->plugin( 'Koha::REST::Plugin::Pagination' ); |
90 |
$self->plugin( 'Koha::REST::Plugin::Query' ); |
124 |
$self->plugin( 'Koha::REST::Plugin::Query' ); |
91 |
- |
|
|