Skip to content

Commit

Permalink
Merge pull request #26 from danielgtaylor/subresource-fix
Browse files Browse the repository at this point in the history
fix: copy router into sub-resources
  • Loading branch information
danielgtaylor committed Feb 23, 2022
2 parents 58fff38 + 11d7e9f commit b8b221c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (r *Resource) SubResource(path string) *Resource {
sub := &Resource{
path: r.path + path,
mux: r.mux.Route(path, nil),
router: r.router,
subResources: []*Resource{},
operations: []*Operation{},
tags: append([]string{}, r.tags...),
Expand Down
9 changes: 9 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,3 +400,12 @@ func TestGetOperationDoesNotCrash(t *testing.T) {
assert.NotNil(t, info)
})
}

func TestSubResource(t *testing.T) {
app := newTestRouter()

// This should not crash.
app.Resource("/").SubResource("/foo").SubResource("/bar").Get("get-bar", "docs", NewResponse(http.StatusOK, "ok")).Run(func(ctx Context) {
// Do nothing
})
}

0 comments on commit b8b221c

Please sign in to comment.