Skip to content

Commit 6328db3

Browse files
committed
Allow statuses sent with Prefer to select the default response
1 parent 8104239 commit 6328db3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

apisprout.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,25 @@ func getExample(negotiator *ContentNegotiator, prefer string, op *openapi3.Opera
180180
other = append(other, s)
181181
}
182182
responses = append(success, other...)
183-
} else {
184-
if op.Responses[prefer] == nil {
185-
return 0, "", blankHeaders, nil, ErrNoExample
186-
}
183+
} else if op.Responses[prefer] != nil {
187184
responses = []string{prefer}
185+
} else if op.Responses["default"] != nil {
186+
responses = []string{"default"}
187+
} else {
188+
return 0, "", blankHeaders, nil, ErrNoExample
188189
}
189190

190191
// Now try to find the first example we can and return it!
191192
for _, s := range responses {
192193
response := op.Responses[s]
193194
status, err := strconv.Atoi(s)
194195
if err != nil {
195-
// Treat default and other named statuses as 200.
196+
// If we are using the default with prefer, we can use its status
197+
// code:
198+
status, err = strconv.Atoi(prefer)
199+
}
200+
if err != nil {
201+
// Otherwise, treat default and other named statuses as 200.
196202
status = http.StatusOK
197203
}
198204

0 commit comments

Comments
 (0)