@@ -, +, @@ --- Koha/REST/Plugin/PluginRoutes.pm | 4 ++- Koha/REST/V1.pm | 61 +++++++++++++++++++------------- 2 files changed, 39 insertions(+), 26 deletions(-) --- a/Koha/REST/Plugin/PluginRoutes.pm +++ a/Koha/REST/Plugin/PluginRoutes.pm @@ -87,7 +87,9 @@ sub inject_routes { return $spec; } catch { - warn "$_"; + my $error = $_; + my $class = ref $plugin; + warn "Plugin $class route injection failed: $error"; return $spec; }; } --- a/Koha/REST/V1.pm +++ a/Koha/REST/V1.pm @@ -20,6 +20,7 @@ use Modern::Perl; use Mojo::Base 'Mojolicious'; use C4::Context; +use Carp; use JSON::Validator::OpenAPI::Mojolicious; use Try::Tiny; @@ -101,31 +102,41 @@ sub startup { catch { # Validation of the complete spec failed. Resort to validation one-by-one # to catch bad ones. - $validator->load_and_validate_schema( - $self->home->rel_file("api/v1/swagger/swagger.json"), - { - allow_invalid_ref => 1, - } - ); - - $spec = $validator->schema->data; - $self->plugin( - 'Koha::REST::Plugin::PluginRoutes' => { - spec => $spec, - validator => $validator - } - ) unless C4::Context->needs_install; # load only if Koha is installed - - $self->plugin( - OpenAPI => { - spec => $spec, - route => $self->routes->under('/api/v1')->to('Auth#under'), - allow_invalid_ref => - 1, # required by our spec because $ref directly under - # Paths-, Parameters-, Definitions- & Info-object - # is not allowed by the OpenAPI specification. - } - ); + + # JSON::Validator uses confess, so trim call stack from the message. + carp "Warning: Could not load REST API spec bundle: " . ($_ =~ /\A(.*?)$/ms)[0]; + + try { + $validator->load_and_validate_schema( + $self->home->rel_file("api/v1/swagger/swagger.json"), + { + allow_invalid_ref => 1, + } + ); + + $spec = $validator->schema->data; + $self->plugin( + 'Koha::REST::Plugin::PluginRoutes' => { + spec => $spec, + validator => $validator + } + ) unless C4::Context->needs_install; # load only if Koha is installed + + $self->plugin( + OpenAPI => { + spec => $spec, + route => $self->routes->under('/api/v1')->to('Auth#under'), + allow_invalid_ref => + 1, # required by our spec because $ref directly under + # Paths-, Parameters-, Definitions- & Info-object + # is not allowed by the OpenAPI specification. + } + ); + } + catch { + # JSON::Validator uses confess, so trim call stack from the message. + croak "Could not load REST API spec: " . ($_ =~ /\A(.*?)$/ms)[0]; + }; }; $self->plugin( 'Koha::REST::Plugin::Pagination' ); --