Skip to content

Commit f78ef39

Browse files
Merge pull request #53 from puppetlabs/upstream/prefer-default
Allow statuses sent with Prefer to select the default response
2 parents 41bde82 + 6328db3 commit f78ef39

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
@@ -183,19 +183,25 @@ func getExample(negotiator *ContentNegotiator, prefer string, op *openapi3.Opera
183183
other = append(other, s)
184184
}
185185
responses = append(success, other...)
186-
} else {
187-
if op.Responses[prefer] == nil {
188-
return 0, "", blankHeaders, nil, ErrNoExample
189-
}
186+
} else if op.Responses[prefer] != nil {
190187
responses = []string{prefer}
188+
} else if op.Responses["default"] != nil {
189+
responses = []string{"default"}
190+
} else {
191+
return 0, "", blankHeaders, nil, ErrNoExample
191192
}
192193

193194
// Now try to find the first example we can and return it!
194195
for _, s := range responses {
195196
response := op.Responses[s]
196197
status, err := strconv.Atoi(s)
197198
if err != nil {
198-
// Treat default and other named statuses as 200.
199+
// If we are using the default with prefer, we can use its status
200+
// code:
201+
status, err = strconv.Atoi(prefer)
202+
}
203+
if err != nil {
204+
// Otherwise, treat default and other named statuses as 200.
199205
status = http.StatusOK
200206
}
201207

0 commit comments

Comments
 (0)