Skip to content

Commit

Permalink
fix issue 407, where if server URL has no path it throws exception (#408
Browse files Browse the repository at this point in the history
)

Co-authored-by: Naer Chang <[email protected]>
  • Loading branch information
NaerChang2 and mcafee-nchang authored Aug 16, 2021
1 parent 9b79d5d commit e2c8b0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion routers/gorillamux/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewRouter(doc *openapi3.T) (routers.Router, error) {
return nil, err
}
path := bDecode(u.EscapedPath())
if path[len(path)-1] == '/' {
if len(path) > 0 && path[len(path)-1] == '/' {
path = path[:len(path)-1]
}
servers = append(servers, srv{
Expand Down
13 changes: 13 additions & 0 deletions routers/gorillamux/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,16 @@ func TestPermuteScheme(t *testing.T) {
perms := permutePart(scheme0, server)
require.Equal(t, []string{"http", "https"}, perms)
}

func TestServerPath(t *testing.T) {
server := &openapi3.Server{URL: "http://example.com"}
err := server.Validate(context.Background())
require.NoError(t, err)

_, err = NewRouter(&openapi3.T{Servers: openapi3.Servers{
server,
&openapi3.Server{URL: "http://example.com/"},
&openapi3.Server{URL: "http://example.com/path"}},
})
require.NoError(t, err)
}

0 comments on commit e2c8b0c

Please sign in to comment.