这是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
12 changes: 12 additions & 0 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ type Resource struct {
operations []*Operation

tags []string

hidden bool
}

func (r *Resource) toOpenAPI(components *oaComponents) *gabs.Container {
if r.hidden {
return nil
}

doc := gabs.New()

for _, sub := range r.subResources {
Expand Down Expand Up @@ -110,3 +116,9 @@ func (r *Resource) SubResource(path string) *Resource {
func (r *Resource) Tags(names ...string) {
r.tags = append(r.tags, names...)
}

// Hidden removes this resource from the OpenAPI spec and documentation. It
// is intended to be used for things like health check endpoints.
func (r *Resource) Hidden() {
r.hidden = true
}
24 changes: 24 additions & 0 deletions resource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package huma

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestResource(t *testing.T) {
r := Resource{
path: "/test",
}

assert.NotNil(t, r.toOpenAPI(&oaComponents{}))
}

func TestHiddenResource(t *testing.T) {
r := Resource{
path: "/test",
}
r.Hidden()

assert.Nil(t, r.toOpenAPI(&oaComponents{}))
}