Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add x-internal #65

Closed
wants to merge 2 commits into from
Closed
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 @@ -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:**
Expand Down
7 changes: 7 additions & 0 deletions fizz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions fizz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions openapi/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type OperationInfo struct {
InputModel interface{}
Responses []*OperationResponse
XCodeSamples []*XCodeSample
XInternal bool
}

// ResponseHeader represents a single header that
Expand Down
1 change: 1 addition & 0 deletions openapi/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion testdata/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"label":"v4.4",
"source":"curl http://0.0.0.0:8080"
}
]
],
"x-internal": true
}
},
"/test/{a}/{b}": {
Expand Down
1 change: 1 addition & 0 deletions testdata/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down