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

(-)a/Koha/REST/Plugin/PluginRoutes.pm (+2 lines)
Lines 69-74 sub register { Link Here
69
sub inject_routes {
69
sub inject_routes {
70
    my ( $spec, $plugin, $validator ) = @_;
70
    my ( $spec, $plugin, $validator ) = @_;
71
71
72
    return merge_spec( $spec, $plugin ) unless $validator;
73
72
    return try {
74
    return try {
73
75
74
        my $backup_spec = merge_spec( clone($spec), $plugin );
76
        my $backup_spec = merge_spec( clone($spec), $plugin );
(-)a/Koha/REST/V1.pm (-25 / +58 lines)
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 67-99 sub startup { Link Here
67
    }
68
    }
68
69
69
    my $validator = JSON::Validator::OpenAPI::Mojolicious->new;
70
    my $validator = JSON::Validator::OpenAPI::Mojolicious->new;
70
    $validator->load_and_validate_schema(
71
        $self->home->rel_file("api/v1/swagger/swagger.json"),
72
        {
73
          allow_invalid_ref  => 1,
74
        }
75
      );
76
71
77
    push @{$self->routes->namespaces}, 'Koha::Plugin';
72
    push @{$self->routes->namespaces}, 'Koha::Plugin';
78
73
79
    my $spec = $validator->schema->data;
74
    # Try to load and merge all schemas first and validate the result just once.
80
    $self->plugin(
75
    my $spec;
81
        'Koha::REST::Plugin::PluginRoutes' => {
76
    try {
82
            spec      => $spec,
77
        $spec = $validator->bundle(
83
            validator => $validator
78
            {
84
        }
79
                replace => 1,
85
    );
80
                schema => $self->home->rel_file("api/v1/swagger/swagger.json")
86
81
            }
87
    $self->plugin(
82
        );
88
        OpenAPI => {
83
89
            spec  => $spec,
84
        $self->plugin(
90
            route => $self->routes->under('/api/v1')->to('Auth#under'),
85
            'Koha::REST::Plugin::PluginRoutes' => {
91
            allow_invalid_ref =>
86
                spec               => $spec,
92
              1,    # required by our spec because $ref directly under
87
                validator          => undef
93
                    # Paths-, Parameters-, Definitions- & Info-object
88
            }
94
                    # is not allowed by the OpenAPI specification.
89
        );
95
        }
90
96
    );
91
        $self->plugin(
92
            OpenAPI => {
93
                spec  => $spec,
94
                route => $self->routes->under('/api/v1')->to('Auth#under'),
95
                allow_invalid_ref =>
96
                1,    # required by our spec because $ref directly under
97
                        # Paths-, Parameters-, Definitions- & Info-object
98
                        # is not allowed by the OpenAPI specification.
99
            }
100
        );
101
    }
102
    catch {
103
        # Validation of the complete spec failed. Resort to validation one-by-one
104
        # to catch bad ones.
105
        $validator->load_and_validate_schema(
106
            $self->home->rel_file("api/v1/swagger/swagger.json"),
107
            {
108
                allow_invalid_ref  => 1,
109
            }
110
        );
111
112
        $spec = $validator->schema->data;
113
        $self->plugin(
114
            'Koha::REST::Plugin::PluginRoutes' => {
115
                spec      => $spec,
116
                validator => $validator
117
            }
118
        );
119
120
        $self->plugin(
121
            OpenAPI => {
122
                spec  => $spec,
123
                route => $self->routes->under('/api/v1')->to('Auth#under'),
124
                allow_invalid_ref =>
125
                1,    # required by our spec because $ref directly under
126
                        # Paths-, Parameters-, Definitions- & Info-object
127
                        # is not allowed by the OpenAPI specification.
128
            }
129
        );
130
    };
97
131
98
    $self->plugin( 'Koha::REST::Plugin::Pagination' );
132
    $self->plugin( 'Koha::REST::Plugin::Pagination' );
99
    $self->plugin( 'Koha::REST::Plugin::Query' );
133
    $self->plugin( 'Koha::REST::Plugin::Query' );
100
- 

Return to bug 24700