diff --git a/resource.go b/resource.go index b9498422..31778d7a 100644 --- a/resource.go +++ b/resource.go @@ -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...), diff --git a/router_test.go b/router_test.go index 4e8cc4bb..06fa0907 100644 --- a/router_test.go +++ b/router_test.go @@ -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 + }) +}