Skip to content

Commit 408c6fc

Browse files
authored
Add x-internal (#64)
feat: add support for the x-internal flag
1 parent 1ced8ff commit 408c6fc

File tree

8 files changed

+18
-1
lines changed

8 files changed

+18
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ fizz.WithoutSecurity()
110110

111111
// Add a Code Sample to the operation.
112112
fizz.XCodeSample(codeSample *XCodeSample)
113+
114+
// Mark the operation as internal. The x-internal flag is interpreted by third-party tools and it only impacts the visual documentation rendering.
115+
fizz.XInternal()
113116
```
114117

115118
**NOTES:**

fizz.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ func WithoutSecurity() func(*openapi.OperationInfo) {
383383
}
384384
}
385385

386+
// XInternal marks the operation as internal.
387+
func XInternal() func(*openapi.OperationInfo) {
388+
return func(o *openapi.OperationInfo) {
389+
o.XInternal = true
390+
}
391+
}
392+
386393
// OperationFromContext returns the OpenAPI operation from
387394
// the givent Gin context or an error if none is found.
388395
func OperationFromContext(c *gin.Context) (*openapi.Operation, error) {

fizz_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ func TestSpecHandler(t *testing.T) {
273273
}),
274274
// Explicit override for SecurityRequirement (allow-all)
275275
WithoutSecurity(),
276+
XInternal(),
276277
},
277278
tonic.Handler(func(c *gin.Context) error {
278279
return nil

openapi/generator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ func (g *Generator) AddOperation(path, method, tag string, in, out reflect.Type,
258258
op.Responses = make(Responses)
259259
op.XCodeSamples = info.XCodeSamples
260260
op.Security = info.Security
261+
op.XInternal = info.XInternal
261262
}
262263
if tag != "" {
263264
op.Tags = append(op.Tags, tag)

openapi/operation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type OperationInfo struct {
1414
Responses []*OperationResponse
1515
Security []*SecurityRequirement
1616
XCodeSamples []*XCodeSample
17+
XInternal bool
1718
}
1819

1920
// ResponseHeader represents a single header that

openapi/spec.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ type Operation struct {
198198
Servers []*Server `json:"servers,omitempty" yaml:"servers,omitempty"`
199199
Security []*SecurityRequirement `json:"security" yaml:"security"`
200200
XCodeSamples []*XCodeSample `json:"x-codeSamples,omitempty" yaml:"x-codeSamples,omitempty"`
201+
XInternal bool `json:"x-internal,omitempty" yaml:"x-internal,omitempty"`
201202
}
202203

203204
// A workaround for missing omitnil functionality.
@@ -213,6 +214,7 @@ type operationNilOmitted struct {
213214
Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
214215
Servers []*Server `json:"servers,omitempty" yaml:"servers,omitempty"`
215216
XCodeSamples []*XCodeSample `json:"x-codeSamples,omitempty" yaml:"x-codeSamples,omitempty"`
217+
XInternal bool `json:"x-internal,omitempty" yaml:"x-internal,omitempty"`
216218
}
217219

218220
// MarshalYAML implements yaml.Marshaler for Operation.

testdata/spec.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@
104104
"source": "curl http://0.0.0.0:8080"
105105
}
106106
],
107-
"security": []
107+
"security": [],
108+
"x-internal": true
108109
}
109110
},
110111
"/test/{a}/{b}": {

testdata/spec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ paths:
6969
label: v4.4
7070
source: curl http://0.0.0.0:8080
7171
security: []
72+
x-internal: true
7273
/test/{a}/{b}:
7374
get:
7475
operationId: GetTest2

0 commit comments

Comments
 (0)