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

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

Return to bug 25504