Bug 28480: Add q parameters for GET /patrons
[koha.git] / xt / api.t
1 # This file is part of Koha.
2 #
3 # Koha is free software; you can redistribute it and/or modify it under the
4 # terms of the GNU General Public License as published by the Free Software
5 # Foundation; either version 3 of the License, or (at your option) any later
6 # version.
7 #
8 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
9 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
10 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with Koha; if not, see <http://www.gnu.org/licenses>.
14
15 use Modern::Perl;
16
17 use Test::More tests => 2;
18
19 use Test::Mojo;
20 use Data::Dumper;
21
22 my $t    = Test::Mojo->new('Koha::REST::V1');
23 my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json;
24
25 my $paths = $spec->{paths};
26
27 my @missing_additionalProperties = ();
28
29 foreach my $route ( keys %{$paths} ) {
30     foreach my $verb ( keys %{ $paths->{$route} } ) {
31
32         # p($paths->{$route}->{$verb});
33
34         # check parameters []
35         foreach my $parameter ( @{ $paths->{$route}->{$verb}->{parameters} } ) {
36             if (   exists $parameter->{schema}
37                 && exists $parameter->{schema}->{type}
38                 && ref( $parameter->{schema}->{type} ) ne 'ARRAY'
39                 && $parameter->{schema}->{type} eq 'object' ) {
40
41                 # it is an object type definition
42                 if ( not exists $parameter->{schema}->{additionalProperties} ) {
43                     push @missing_additionalProperties,
44                       { type  => 'parameter',
45                         route => $route,
46                         verb  => $verb,
47                         name  => $parameter->{name}
48                       };
49                 }
50             }
51         }
52
53         # check responses  {}
54         my $responses = $paths->{$route}->{$verb}->{responses};
55         foreach my $response ( keys %{$responses} ) {
56             if (   exists $responses->{$response}->{schema}
57                 && exists $responses->{$response}->{schema}->{type}
58                 && ref( $responses->{$response}->{schema}->{type} ) ne 'ARRAY'
59                 && $responses->{$response}->{schema}->{type} eq 'object' ) {
60
61                 # it is an object type definition
62                 if ( not exists $responses->{$response}->{schema}->{additionalProperties} ) {
63                     push @missing_additionalProperties,
64                       { type  => 'response',
65                         route => $route,
66                         verb  => $verb,
67                         name  => $response
68                       };
69                 }
70             }
71         }
72     }
73 }
74
75 is( scalar @missing_additionalProperties, 0 )
76   or diag Dumper \@missing_additionalProperties;