Skip to content

Commit

Permalink
restore path-searching logic to fix #107
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Feb 9, 2019
1 parent 9378fb8 commit fe3889c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/Mojolicious/Plugin/OpenAPI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,11 @@ sub _helper_get_spec {

return $self->validator->get($path) if ref $path or $path =~ m!^/! or !length $path;

my $jp;
for my $s (reverse @{$c->match->stack}) {
$jp ||= [paths => $s->{'openapi.path'}];
}

push @$jp, lc $c->req->method if $jp and $path ne 'for_path'; # Internal for now
return $jp ? $self->validator->get($jp) : undef;
my ($op_path) = grep $_, map $_->{'openapi.path'}, reverse @{$c->match->stack};
return undef if !$op_path;
my $jp = [paths => $op_path];
push @$jp, lc $c->req->method if $path ne 'for_path'; # Internal for now
return $self->validator->get($jp);
}

sub _helper_reply {
Expand Down
1 change: 1 addition & 0 deletions t/authenticate.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ plugin OpenAPI => {route => $auth, url => 'data://main/api.json'};
my $t = Test::Mojo->new;

$t->get_ok('/api/login')->status_is(200)->json_is('/id', 123);
$t->get_ok('/api')->status_is(401)->json_is('/errors/0/message', 'not logged in');
$t->get_ok('/api/protected')->status_is(401)->json_is('/errors/0/message', 'not logged in');
$t->get_ok('/api/protected?unsafe_token=1')->status_is(200)->json_is('/protected', 'secret');

Expand Down

0 comments on commit fe3889c

Please sign in to comment.