这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ func TestGroupNoPrefix(t *testing.T) {
assert.Equal(t, http.StatusNoContent, resp.Result().StatusCode)
}

func TestGroupEmptyPath(t *testing.T) {
_, api := humatest.New(t)

grp := huma.NewGroup(api, "/users")

huma.Get(grp, "", func(ctx context.Context, input *struct{}) (*struct{}, error) {
return nil, nil
})

assert.Nil(t, api.OpenAPI().Paths["/"])
assert.Nil(t, api.OpenAPI().Paths[""])
assert.NotNil(t, api.OpenAPI().Paths["/users"])

resp := api.Get("/users")
assert.Equal(t, http.StatusNoContent, resp.Result().StatusCode)

}

func TestGroupMultiPrefix(t *testing.T) {
_, api := humatest.New(t)

Expand Down
9 changes: 7 additions & 2 deletions huma.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,13 @@
oapi := api.OpenAPI()
registry := oapi.Components.Schemas

if op.Method == "" || op.Path == "" {
panic("method and path must be specified in operation")
if op.Method == "" {
panic("method must be specified in operation")

Check warning on line 626 in huma.go

View check run for this annotation

Codecov / codecov/patch

huma.go#L626

Added line #L626 was not covered by tests
}
if op.Path == "" {
if grp, ok := api.(*Group); !ok || len(grp.prefixes) == 0 {
panic("path must be specified in operation")

Check warning on line 630 in huma.go

View check run for this annotation

Codecov / codecov/patch

huma.go#L630

Added line #L630 was not covered by tests
}
}
initResponses(&op)

Expand Down
Loading