这是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
11 changes: 11 additions & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Operation struct {
responses []Response
maxBodyBytes int64
bodyReadTimeout time.Duration
deprecated bool
}

func newOperation(resource *Resource, method, id, docs string, responses []Response) *Operation {
Expand All @@ -72,6 +73,7 @@ func newOperation(resource *Resource, method, id, docs string, responses []Respo
maxBodyBytes: 1024 * 1024,
// 15 second timeout by default
bodyReadTimeout: resource.router.defaultBodyReadTimeout,
deprecated: false,
}
}

Expand All @@ -85,6 +87,9 @@ func (o *Operation) toOpenAPI(components *oaComponents) *gabs.Container {
if o.description != "" {
doc.Set(o.description, "description")
}
if o.deprecated {
doc.Set(o.deprecated, "deprecated")
}

// Request params
for _, param := range o.params {
Expand Down Expand Up @@ -188,6 +193,12 @@ func (o *Operation) RequestSchema(s *schema.Schema) {
o.RequestSchemaForContentType("application/json", s)
}

// Deprecated marks the operation is deprecated, warning consumers should
// refrain from using this.
func (o *Operation) Deprecated() {
o.deprecated = true
}

func (o *Operation) RequestSchemaForContentType(ct string, s *schema.Schema) {
if o.requests[ct] == nil {
o.requests[ct] = &request{}
Expand Down
22 changes: 22 additions & 0 deletions operation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package huma

import (
"testing"

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

func TestOperation(t *testing.T) {
op := Operation{}

assert.Equal(t, op.toOpenAPI(&oaComponents{}).Data(), map[string]interface{}{
"operationId": "",
})
}

func TestDeprecatedOperation(t *testing.T) {
op := Operation{}
op.Deprecated()

assert.Contains(t, op.toOpenAPI(&oaComponents{}).Data(), "deprecated")
}