View | Details | Raw Unified | Return to bug 25504
Collapse All | Expand All

(-)a/Koha/REST/Plugin/PluginRoutes.pm (-1 / +3 lines)
Lines 87-93 sub inject_routes { Link Here
87
        return $spec;
87
        return $spec;
88
    }
88
    }
89
    catch {
89
    catch {
90
        warn "$_";
90
        my $error = $_;
91
        my $class = ref $plugin;
92
        warn "Plugin $class route injection failed: $error";
91
        return $spec;
93
        return $spec;
92
    };
94
    };
93
}
95
}
(-)a/Koha/REST/V1.pm (-26 / +36 lines)
Lines 20-25 use Modern::Perl; Link Here
20
use Mojo::Base 'Mojolicious';
20
use Mojo::Base 'Mojolicious';
21
21
22
use C4::Context;
22
use C4::Context;
23
use Carp;
23
use JSON::Validator::OpenAPI::Mojolicious;
24
use JSON::Validator::OpenAPI::Mojolicious;
24
use Try::Tiny;
25
use Try::Tiny;
25
26
Lines 101-131 sub startup { Link Here
101
    catch {
102
    catch {
102
        # Validation of the complete spec failed. Resort to validation one-by-one
103
        # Validation of the complete spec failed. Resort to validation one-by-one
103
        # to catch bad ones.
104
        # to catch bad ones.
104
        $validator->load_and_validate_schema(
105
        
105
            $self->home->rel_file("api/v1/swagger/swagger.json"),
106
        # JSON::Validator uses confess, so trim call stack from the message.
106
            {
107
        carp "Warning: Could not load REST API spec bundle: " . ($_ =~ /\A(.*?)$/ms)[0]; 
107
                allow_invalid_ref  => 1,
108
108
            }
109
        try {
109
        );
110
            $validator->load_and_validate_schema(
110
111
                $self->home->rel_file("api/v1/swagger/swagger.json"),
111
        $spec = $validator->schema->data;
112
                {
112
        $self->plugin(
113
                    allow_invalid_ref  => 1,
113
            'Koha::REST::Plugin::PluginRoutes' => {
114
                }
114
                spec      => $spec,
115
            );
115
                validator => $validator
116
116
            }
117
            $spec = $validator->schema->data;
117
        )  unless C4::Context->needs_install; # load only if Koha is installed
118
            $self->plugin(
118
119
                'Koha::REST::Plugin::PluginRoutes' => {
119
        $self->plugin(
120
                    spec      => $spec,
120
            OpenAPI => {
121
                    validator => $validator
121
                spec  => $spec,
122
                }
122
                route => $self->routes->under('/api/v1')->to('Auth#under'),
123
            )  unless C4::Context->needs_install; # load only if Koha is installed
123
                allow_invalid_ref =>
124
124
                1,    # required by our spec because $ref directly under
125
            $self->plugin(
125
                        # Paths-, Parameters-, Definitions- & Info-object
126
                OpenAPI => {
126
                        # is not allowed by the OpenAPI specification.
127
                    spec  => $spec,
127
            }
128
                    route => $self->routes->under('/api/v1')->to('Auth#under'),
128
        );
129
                    allow_invalid_ref =>
130
                    1,    # required by our spec because $ref directly under
131
                            # Paths-, Parameters-, Definitions- & Info-object
132
                            # is not allowed by the OpenAPI specification.
133
                }
134
            );
135
        }
136
        catch {
137
            # JSON::Validator uses confess, so trim call stack from the message.
138
            croak "Could not load REST API spec: " . ($_ =~ /\A(.*?)$/ms)[0];
139
        };
129
    };
140
    };
130
141
131
    $self->plugin( 'Koha::REST::Plugin::Pagination' );
142
    $self->plugin( 'Koha::REST::Plugin::Pagination' );
132
- 

Return to bug 25504