diff --git a/README.md b/README.md index be995e1..581551e 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,9 @@ fizz.XCodeSample(codeSample *XCodeSample) // Mark the operation as internal. The x-internal flag is interpreted by third-party tools and it only impacts the visual documentation rendering. fizz.XInternal() + +// Add additional tags to the operation. +fizz.WithTags(tags ...string) ``` **NOTES:** diff --git a/fizz.go b/fizz.go index 7339898..fee5ebc 100644 --- a/fizz.go +++ b/fizz.go @@ -401,6 +401,12 @@ func XInternal() func(*openapi.OperationInfo) { } } +func WithTags(tags ...string) func(*openapi.OperationInfo) { + return func(o *openapi.OperationInfo) { + o.Tags = tags + } +} + // OperationFromContext returns the OpenAPI operation from // the given Gin context or an error if none is found. func OperationFromContext(ctx context.Context) (*openapi.Operation, error) { diff --git a/fizz_test.go b/fizz_test.go index c5fd7af..3d11d91 100644 --- a/fizz_test.go +++ b/fizz_test.go @@ -308,6 +308,7 @@ func TestSpecHandler(t *testing.T) { // Explicit override for SecurityRequirement (allow-all) WithoutSecurity(), XInternal(), + WithTags("TestTag1", "TestTag2"), }, tonic.Handler(func(c *gin.Context, in *testInputModel1) (*T, error) { return &T{}, nil diff --git a/openapi/generator.go b/openapi/generator.go index 99f6833..912012a 100644 --- a/openapi/generator.go +++ b/openapi/generator.go @@ -265,6 +265,7 @@ func (g *Generator) AddOperation(path, method, tag string, in, out reflect.Type, op.XCodeSamples = info.XCodeSamples op.Security = info.Security op.XInternal = info.XInternal + op.Tags = info.Tags } if tag != "" { op.Tags = append(op.Tags, tag) diff --git a/openapi/operation.go b/openapi/operation.go index 306900f..f35e81c 100644 --- a/openapi/operation.go +++ b/openapi/operation.go @@ -15,6 +15,7 @@ type OperationInfo struct { Security []*SecurityRequirement XCodeSamples []*XCodeSample XInternal bool + Tags []string } // ResponseHeader represents a single header that diff --git a/testdata/spec.json b/testdata/spec.json index ea89455..f74ec17 100644 --- a/testdata/spec.json +++ b/testdata/spec.json @@ -126,7 +126,8 @@ } ], "security": [], - "x-internal": true + "x-internal": true, + "tags": ["TestTag1", "TestTag2"] } }, "/test/{a}/{b}": { diff --git a/testdata/spec.yaml b/testdata/spec.yaml index 4d64d93..e8e6df7 100644 --- a/testdata/spec.yaml +++ b/testdata/spec.yaml @@ -80,6 +80,9 @@ paths: source: curl http://0.0.0.0:8080 security: [] x-internal: true + tags: + - TestTag1 + - TestTag2 /test/{a}/{b}: get: operationId: GetTest2