mirror of
https://github.com/Fishwaldo/huma.git
synced 2025-03-15 11:21:42 +00:00
feat: allow hidden/undocumented resources
This commit is contained in:
parent
73c101e7f0
commit
09ba8cfa37
2 changed files with 36 additions and 0 deletions
12
resource.go
12
resource.go
|
@ -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 {
|
||||
|
@ -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
resource_test.go
Normal file
24
resource_test.go
Normal file
|
@ -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{}))
|
||||
}
|
Loading…
Add table
Reference in a new issue