1 # This file is part of Koha.
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
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.
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>.
17 use Test::More tests => 3;
23 use IPC::Cmd qw(can_run);
25 my $t = Test::Mojo->new('Koha::REST::V1');
26 my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json;
28 my $paths = $spec->{paths};
30 my @missing_additionalProperties = ();
32 foreach my $route ( keys %{$paths} ) {
33 foreach my $verb ( keys %{ $paths->{$route} } ) {
35 # p($paths->{$route}->{$verb});
38 foreach my $parameter ( @{ $paths->{$route}->{$verb}->{parameters} } ) {
39 if ( exists $parameter->{schema}
40 && exists $parameter->{schema}->{type}
41 && ref( $parameter->{schema}->{type} ) ne 'ARRAY'
42 && $parameter->{schema}->{type} eq 'object' ) {
44 # it is an object type definition
45 if ( $parameter->{name} ne 'query' # our query parameter is under-specified
46 and not exists $parameter->{schema}->{additionalProperties} ) {
47 push @missing_additionalProperties,
48 { type => 'parameter',
51 name => $parameter->{name}
58 my $responses = $paths->{$route}->{$verb}->{responses};
59 foreach my $response ( keys %{$responses} ) {
60 if ( exists $responses->{$response}->{schema}
61 && exists $responses->{$response}->{schema}->{type}
62 && ref( $responses->{$response}->{schema}->{type} ) ne 'ARRAY'
63 && $responses->{$response}->{schema}->{type} eq 'object' ) {
65 # it is an object type definition
66 if ( not exists $responses->{$response}->{schema}->{additionalProperties} ) {
67 push @missing_additionalProperties,
79 is( scalar @missing_additionalProperties, 0 )
80 or diag Dumper \@missing_additionalProperties;
82 subtest 'The spec passes the swagger-cli validation' => sub {
87 skip "Skipping tests, swagger-cli missing", 1
88 unless can_run('swagger-cli');
90 my $spec_dir = "$FindBin::Bin/../api/v1/swagger";
91 my $var = qx{swagger-cli validate $spec_dir/swagger.yaml 2>&1};
92 is( $?, 0, 'Validation exit code is 0' )