Skip to content
Open
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down
6 changes: 6 additions & 0 deletions fizz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions fizz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions openapi/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type OperationInfo struct {
Security []*SecurityRequirement
XCodeSamples []*XCodeSample
XInternal bool
Tags []string
}

// ResponseHeader represents a single header that
Expand Down
3 changes: 2 additions & 1 deletion testdata/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
}
],
"security": [],
"x-internal": true
"x-internal": true,
"tags": ["TestTag1", "TestTag2"]
}
},
"/test/{a}/{b}": {
Expand Down
3 changes: 3 additions & 0 deletions testdata/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down