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>.
16 use File::Slurp qw( read_file );
17 use JSON qw( from_json );
18 use Test::More tests => 4;
23 my $definitions_dir = 'api/v1/swagger/definitions';
24 opendir( $dh, $definitions_dir ) or die "$!";
25 my @files = readdir $dh;
26 my @wrong_additionalProperties;
27 ok( @files, "making sure we found definitions files" );
28 for my $file (@files) {
29 next unless $file =~ m|\.json$|;
30 my $spec = from_json read_file("$definitions_dir/$file");
31 if ( not exists $spec->{additionalProperties}
32 or $spec->{additionalProperties} != 0 )
34 push @wrong_additionalProperties, { file => $file, };
37 is( scalar @wrong_additionalProperties, 0 )
38 or diag Dumper \@wrong_additionalProperties;
41 my $paths_dir = 'api/v1/swagger/paths';
42 opendir( $dh, $paths_dir ) or die "$!";
44 @wrong_additionalProperties = ();
45 ok(@files, "making sure we found paths files");
46 for my $file (@files) {
47 next unless $file =~ m|\.json$|;
48 my $spec = from_json read_file("$paths_dir/$file");
49 for my $route ( keys %$spec ) {
50 for my $method ( keys %{ $spec->{$route} } ) {
51 next if $method ne 'post' && $method ne 'put';
52 for my $parameter ( @{ $spec->{$route}->{$method}->{parameters} } ) {
53 if ( exists $parameter->{schema} ) {
55 # If it's a ref we inherit from the definition file
56 next if exists $parameter->{schema}->{'$ref'};
58 if ( not exists $parameter->{schema}->{additionalProperties}
59 or $parameter->{schema}->{additionalProperties} != 0 )
61 push @wrong_additionalProperties,
63 file => "$paths_dir/$file",
74 is( scalar @wrong_additionalProperties, 0 )
75 or diag Dumper \@wrong_additionalProperties;