Skip to content
Merged
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
7 changes: 7 additions & 0 deletions fizz.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ func ResponseWithExamples(statusCode, desc string, model interface{}, headers []
}
}

// DefaultResponseExamples adds additional examples to the default response.
func DefaultResponseExamples(examples map[string]interface{}) func(*openapi.OperationInfo) {
return func(o *openapi.OperationInfo) {
o.DefaultResponseExamples = examples
}
}

// Header adds a header to the operation.
func Header(name, desc string, model interface{}) func(*openapi.OperationInfo) {
return func(o *openapi.OperationInfo) {
Expand Down
4 changes: 2 additions & 2 deletions openapi/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (g *Generator) AddOperation(path, method, tag string, in, out reflect.Type,
// Generate the default response from the tonic
// handler return type. If the handler has no output
// type, the response won't have a schema.
if err := g.setOperationResponse(op, out, strconv.Itoa(info.StatusCode), tonic.MediaType(), info.StatusDescription, info.Headers, nil, nil); err != nil {
if err := g.setOperationResponse(op, out, strconv.Itoa(info.StatusCode), tonic.MediaType(), info.StatusDescription, info.Headers, nil, info.DefaultResponseExamples); err != nil {
return nil, err
}
// Generate additional responses from the operation
Expand Down Expand Up @@ -1255,7 +1255,7 @@ func fieldNameFromTag(sf reflect.StructField, tagName string) string {
return name
}

/// parseExampleValue is used to transform the string representation of the example value to the correct type.
// parseExampleValue is used to transform the string representation of the example value to the correct type.
func parseExampleValue(t reflect.Type, value string) (interface{}, error) {
// If the type implements Exampler use the ParseExample method to create the example
i, ok := reflect.New(t).Interface().(Exampler)
Expand Down
25 changes: 13 additions & 12 deletions openapi/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package openapi
// OperationInfo represents the informations of an operation
// that will be used when generating the OpenAPI specification.
type OperationInfo struct {
ID string
StatusCode int
StatusDescription string
Headers []*ResponseHeader
Summary string
Description string
Deprecated bool
InputModel interface{}
Responses []*OperationResponse
Security []*SecurityRequirement
XCodeSamples []*XCodeSample
XInternal bool
ID string
StatusCode int
StatusDescription string
Headers []*ResponseHeader
Summary string
Description string
Deprecated bool
InputModel interface{}
Responses []*OperationResponse
Security []*SecurityRequirement
XCodeSamples []*XCodeSample
XInternal bool
DefaultResponseExamples map[string]interface{}
}

// ResponseHeader represents a single header that
Expand Down
Loading