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

(-)a/xt/api.t (-2 / +75 lines)
Lines 21-27 use Data::Dumper; Link Here
21
21
22
use FindBin();
22
use FindBin();
23
use IPC::Cmd        qw(can_run);
23
use IPC::Cmd        qw(can_run);
24
use List::MoreUtils qw(any);
24
use List::MoreUtils qw(any none);
25
use File::Slurp     qw(read_file);
25
use File::Slurp     qw(read_file);
26
26
27
my $t    = Test::Mojo->new('Koha::REST::V1');
27
my $t    = Test::Mojo->new('Koha::REST::V1');
Lines 172-177 subtest '400 response tests' => sub { Link Here
172
    }
172
    }
173
};
173
};
174
174
175
subtest 'GET routes parameters tests' => sub {
176
177
    plan tests => 1;
178
179
    my @errors;
180
181
    foreach my $route ( sort keys %{$paths} ) {
182
        foreach my $verb ( keys %{ $paths->{$route} } ) {
183
184
            next unless $verb eq 'get';
185
186
            if (   $paths->{$route}->{$verb}->{operationId} !~ m/^list/
187
                && $paths->{$route}->{$verb}->{operationId} !~ m/^get/ )
188
            {
189
                push @errors,
190
                    sprintf(
191
                    "%s %s -> bad operationId: %s (must start with list or get)", $verb, $route,
192
                    $paths->{$route}->{$verb}->{operationId}
193
                    );
194
                next;
195
            }
196
197
            my @parameters = @{ $paths->{$route}->{$verb}->{parameters} };
198
199
            my $plural = ( any { $_->{in} eq 'body' && $_->{name} eq 'query' } @parameters )
200
                || ( any { $_->{in} eq 'query' && $_->{name} eq 'q' } @parameters );
201
202
            if ($plural) {
203
204
                # 'q' as query parameter needs to be supported
205
                if ( none { $_->{in} eq 'query' && $_->{name} eq 'q' } @parameters ) {
206
                    push @errors, sprintf( "%s %s -> missing 'q' parameter", $verb, $route );
207
                }
208
209
                # 'query' in body needs to be supported
210
                if ( none { $_->{in} eq 'body' && $_->{name} eq 'query' } @parameters ) {
211
                    push @errors, sprintf( "%s %s -> missing 'query' parameter", $verb, $route );
212
                }
213
214
                # plural lists should have match for datatables compatibility
215
                if ( none { $_->{ref} && $_->{ref} eq '../swagger.yaml#/parameters/match' } @parameters ) {
216
                    push @errors, sprintf( "%s %s -> missing 'match' parameter", $verb, $route );
217
                }
218
219
                # plural lists should have order_by for datatables compatibility
220
                if ( none { $_->{ref} && $_->{ref} eq '../swagger.yaml#/parameters/order_by' } @parameters ) {
221
                    push @errors, sprintf( "%s %s -> missing 'order_by' parameter", $verb, $route );
222
                }
223
224
                # plural lists should have page for datatables compatibility
225
                if ( none { $_->{ref} && $_->{ref} eq '../swagger.yaml#/parameters/page' } @parameters ) {
226
                    push @errors, sprintf( "%s %s -> missing 'page' parameter", $verb, $route );
227
                }
228
229
                # plural lists should have per_page for datatables compatibility
230
                if ( none { $_->{ref} && $_->{ref} eq '../swagger.yaml#/parameters/per_page' } @parameters ) {
231
                    push @errors, sprintf( "%s %s -> missing 'per_page' parameter", $verb, $route );
232
                }
233
234
                # plural lists should have request_id_header for datatables compatibility
235
                if ( none { $_->{ref} && $_->{ref} eq '../swagger.yaml#/parameters/request_id_header' } @parameters ) {
236
                    push @errors, sprintf( "%s %s -> missing request_id_header parameter", $verb, $route );
237
                }
238
            }
239
        }
240
    }
241
242
    is( scalar @errors, 0, 'No errors in GET endpoints definitions in the spec' );
243
244
    foreach my $error (@errors) {
245
        print STDERR "$error\n";
246
    }
247
};
248
175
subtest 'POST (201) have location header' => sub {
249
subtest 'POST (201) have location header' => sub {
176
    my @files = `git ls-files 'Koha/REST/V1/**/*.pm'`;
250
    my @files = `git ls-files 'Koha/REST/V1/**/*.pm'`;
177
    plan tests => scalar @files;
251
    plan tests => scalar @files;
178
- 

Return to bug 39817