|
Lines 14-26
Link Here
|
| 14 |
|
14 |
|
| 15 |
use Modern::Perl; |
15 |
use Modern::Perl; |
| 16 |
|
16 |
|
| 17 |
use Test::More tests => 3; |
17 |
use Test::More tests => 4; |
| 18 |
|
18 |
|
| 19 |
use Test::Mojo; |
19 |
use Test::Mojo; |
| 20 |
use Data::Dumper; |
20 |
use Data::Dumper; |
| 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 |
|
25 |
|
| 25 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
26 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 26 |
my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json; |
27 |
my $spec = $t->get_ok( '/api/v1/', 'Correctly fetched the spec' )->tx->res->json; |
|
Lines 39-55
foreach my $route ( keys %{$paths} ) {
Link Here
|
| 39 |
if ( exists $parameter->{schema} |
40 |
if ( exists $parameter->{schema} |
| 40 |
&& exists $parameter->{schema}->{type} |
41 |
&& exists $parameter->{schema}->{type} |
| 41 |
&& ref( $parameter->{schema}->{type} ) ne 'ARRAY' |
42 |
&& ref( $parameter->{schema}->{type} ) ne 'ARRAY' |
| 42 |
&& $parameter->{schema}->{type} eq 'object' ) { |
43 |
&& $parameter->{schema}->{type} eq 'object' ) |
|
|
44 |
{ |
| 43 |
|
45 |
|
| 44 |
# it is an object type definition |
46 |
# it is an object type definition |
| 45 |
if ( $parameter->{name} ne 'query' # our query parameter is under-specified |
47 |
if ( |
| 46 |
and not exists $parameter->{schema}->{additionalProperties} ) { |
48 |
$parameter->{name} ne 'query' # our query parameter is under-specified |
|
|
49 |
and not exists $parameter->{schema}->{additionalProperties} |
| 50 |
) |
| 51 |
{ |
| 47 |
push @missing_additionalProperties, |
52 |
push @missing_additionalProperties, |
| 48 |
{ type => 'parameter', |
53 |
{ |
|
|
54 |
type => 'parameter', |
| 49 |
route => $route, |
55 |
route => $route, |
| 50 |
verb => $verb, |
56 |
verb => $verb, |
| 51 |
name => $parameter->{name} |
57 |
name => $parameter->{name} |
| 52 |
}; |
58 |
}; |
| 53 |
} |
59 |
} |
| 54 |
} |
60 |
} |
| 55 |
} |
61 |
} |
|
Lines 60-75
foreach my $route ( keys %{$paths} ) {
Link Here
|
| 60 |
if ( exists $responses->{$response}->{schema} |
66 |
if ( exists $responses->{$response}->{schema} |
| 61 |
&& exists $responses->{$response}->{schema}->{type} |
67 |
&& exists $responses->{$response}->{schema}->{type} |
| 62 |
&& ref( $responses->{$response}->{schema}->{type} ) ne 'ARRAY' |
68 |
&& ref( $responses->{$response}->{schema}->{type} ) ne 'ARRAY' |
| 63 |
&& $responses->{$response}->{schema}->{type} eq 'object' ) { |
69 |
&& $responses->{$response}->{schema}->{type} eq 'object' ) |
|
|
70 |
{ |
| 64 |
|
71 |
|
| 65 |
# it is an object type definition |
72 |
# it is an object type definition |
| 66 |
if ( not exists $responses->{$response}->{schema}->{additionalProperties} ) { |
73 |
if ( not exists $responses->{$response}->{schema}->{additionalProperties} ) { |
| 67 |
push @missing_additionalProperties, |
74 |
push @missing_additionalProperties, |
| 68 |
{ type => 'response', |
75 |
{ |
|
|
76 |
type => 'response', |
| 69 |
route => $route, |
77 |
route => $route, |
| 70 |
verb => $verb, |
78 |
verb => $verb, |
| 71 |
name => $response |
79 |
name => $response |
| 72 |
}; |
80 |
}; |
| 73 |
} |
81 |
} |
| 74 |
} |
82 |
} |
| 75 |
} |
83 |
} |
|
Lines 77-95
foreach my $route ( keys %{$paths} ) {
Link Here
|
| 77 |
} |
85 |
} |
| 78 |
|
86 |
|
| 79 |
is( scalar @missing_additionalProperties, 0 ) |
87 |
is( scalar @missing_additionalProperties, 0 ) |
| 80 |
or diag Dumper \@missing_additionalProperties; |
88 |
or diag Dumper \@missing_additionalProperties; |
| 81 |
|
89 |
|
| 82 |
subtest 'The spec passes the swagger-cli validation' => sub { |
90 |
subtest 'The spec passes the swagger-cli validation' => sub { |
| 83 |
|
91 |
|
| 84 |
plan tests => 1; |
92 |
plan tests => 1; |
| 85 |
|
93 |
|
| 86 |
SKIP: { |
94 |
SKIP: { |
| 87 |
skip "Skipping tests, swagger-cli missing", 1 |
95 |
skip "Skipping tests, swagger-cli missing", 1 |
| 88 |
unless can_run('swagger-cli'); |
96 |
unless can_run('swagger-cli'); |
| 89 |
|
97 |
|
| 90 |
my $spec_dir = "$FindBin::Bin/../api/v1/swagger"; |
98 |
my $spec_dir = "$FindBin::Bin/../api/v1/swagger"; |
| 91 |
my $var = qx{swagger-cli validate $spec_dir/swagger.yaml 2>&1}; |
99 |
my $var = qx{swagger-cli validate $spec_dir/swagger.yaml 2>&1}; |
| 92 |
is( $?, 0, 'Validation exit code is 0' ) |
100 |
is( $?, 0, 'Validation exit code is 0' ) |
| 93 |
or diag $var; |
101 |
or diag $var; |
|
|
102 |
} |
| 103 |
}; |
| 104 |
|
| 105 |
subtest 'tags tests' => sub { |
| 106 |
|
| 107 |
plan tests => 1; |
| 108 |
|
| 109 |
my @top_level_tags = map { $_->{name} } @{ $spec->{tags} }; |
| 110 |
|
| 111 |
my @errors; |
| 112 |
|
| 113 |
foreach my $route ( keys %{$paths} ) { |
| 114 |
foreach my $verb ( keys %{ $paths->{$route} } ) { |
| 115 |
my @tags = @{ $paths->{$route}->{$verb}->{tags} }; |
| 116 |
|
| 117 |
# Check tag has an entry in the top level tags section |
| 118 |
foreach my $tag (@tags) { |
| 119 |
push @errors, "$verb $route -> uses tag '$tag' not present in top level list" |
| 120 |
unless any { $_ eq $tag } @top_level_tags; |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
is_deeply( \@errors, [], 'No tag errors in the spec' ); |
| 126 |
|
| 127 |
foreach my $error (@errors) { |
| 128 |
print STDERR "$error\n"; |
| 94 |
} |
129 |
} |
| 95 |
}; |
130 |
}; |
| 96 |
- |
|
|