1 package Koha::REST::Plugin::PluginRoutes;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 use Mojo::Base 'Mojolicious::Plugin';
20 use Koha::Exceptions::Plugin;
28 Koha::REST::Plugin::PluginRoutes
39 my ( $self, $app, $config ) = @_;
41 my $spec = $config->{spec};
42 my $validator = $config->{validator};
46 if ( C4::Context->preference('UseKohaPlugins')
47 && C4::Context->config("enable_plugins") )
49 @plugins = Koha::Plugins->new()->GetPlugins(
51 method => 'api_routes',
54 # plugin needs to define a namespace
55 @plugins = grep { $_->api_namespace } @plugins;
58 foreach my $plugin ( @plugins ) {
59 $spec = inject_routes( $spec, $plugin, $validator );
70 my ( $spec, $plugin, $validator ) = @_;
74 my $backup_spec = merge_spec( clone($spec), $plugin );
75 if ( spec_ok( $backup_spec, $validator ) ) {
76 $spec = merge_spec( $spec, $plugin );
79 Koha::Exceptions::Plugin->throw(
80 "The resulting spec is invalid. Skipping " . $plugin->get_metadata->{name}
97 my ( $spec, $plugin ) = @_;
99 my $plugin_spec = $plugin->api_routes;
101 foreach my $route ( keys %{ $plugin_spec } ) {
103 my $THE_route = '/contrib/' . $plugin->api_namespace . $route;
104 if ( exists $spec->{ $THE_route } ) {
105 # Route exists, overwriting is forbidden
106 Koha::Exceptions::Plugin::ForbiddenAction->throw(
107 "Attempted to overwrite $THE_route"
111 $spec->{'paths'}->{ $THE_route } = $plugin_spec->{ $route };
122 my ( $spec, $validator ) = @_;
125 $validator->load_and_validate_schema(
128 allow_invalid_ref => 1,