diff --git a/README.md b/README.md index ea267bb..ee50c18 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,9 @@ fizz.InputModel(model interface{}) // Add a Code Sample to the operation. fizz.XCodeSample(codeSample *XCodeSample) + +// Mark the operation as internal or external. +fizz.XInternal(isInternal bool) ``` **NOTES:** diff --git a/fizz.go b/fizz.go index 306df3f..17fe6aa 100644 --- a/fizz.go +++ b/fizz.go @@ -360,6 +360,13 @@ func XCodeSample(cs *openapi.XCodeSample) func(*openapi.OperationInfo) { } } +// XInternal marks the operation as internal or external. +func XInternal(isInternal bool) func(*openapi.OperationInfo) { + return func(o *openapi.OperationInfo) { + o.XInternal = isInternal + } +} + // OperationFromContext returns the OpenAPI operation from // the givent Gin context or an error if none is found. func OperationFromContext(c *gin.Context) (*openapi.Operation, error) { diff --git a/fizz_test.go b/fizz_test.go index 62f5ba4..562f53b 100644 --- a/fizz_test.go +++ b/fizz_test.go @@ -271,6 +271,7 @@ func TestSpecHandler(t *testing.T) { Label: "v4.4", Source: "curl http://0.0.0.0:8080", }), + XInternal(true), }, tonic.Handler(func(c *gin.Context) error { return nil diff --git a/openapi/generator.go b/openapi/generator.go index e4202c5..9e81b75 100644 --- a/openapi/generator.go +++ b/openapi/generator.go @@ -251,6 +251,7 @@ func (g *Generator) AddOperation(path, method, tag string, in, out reflect.Type, op.Deprecated = info.Deprecated op.Responses = make(Responses) op.XCodeSamples = info.XCodeSamples + op.XInternal = info.XInternal } if tag != "" { op.Tags = append(op.Tags, tag) diff --git a/openapi/operation.go b/openapi/operation.go index 9b43343..2093666 100644 --- a/openapi/operation.go +++ b/openapi/operation.go @@ -13,6 +13,7 @@ type OperationInfo struct { InputModel interface{} Responses []*OperationResponse XCodeSamples []*XCodeSample + XInternal bool } // ResponseHeader represents a single header that diff --git a/openapi/spec.go b/openapi/spec.go index 19ea949..6f2bbba 100644 --- a/openapi/spec.go +++ b/openapi/spec.go @@ -194,6 +194,7 @@ type Operation struct { Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"` Servers []*Server `json:"servers,omitempty" yaml:"servers,omitempty"` XCodeSamples []*XCodeSample `json:"x-codeSamples,omitempty" yaml:"x-codeSamples,omitempty"` + XInternal bool `json:"x-internal,omitempty" yaml:"x-internal,omitempty"` } // Responses represents a container for the expected responses diff --git a/testdata/spec.json b/testdata/spec.json index 1e23c32..eefabee 100644 --- a/testdata/spec.json +++ b/testdata/spec.json @@ -94,7 +94,8 @@ "label":"v4.4", "source":"curl http://0.0.0.0:8080" } - ] + ], + "x-internal": true } }, "/test/{a}/{b}": { diff --git a/testdata/spec.yaml b/testdata/spec.yaml index 6640e3e..3f48483 100644 --- a/testdata/spec.yaml +++ b/testdata/spec.yaml @@ -63,6 +63,7 @@ paths: - lang: Shell label: v4.4 source: curl http://0.0.0.0:8080 + x-internal: true /test/{a}/{b}: get: operationId: GetTest2