Skip to content

Commit

Permalink
Responses Object MUST contain at least one response code (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored Jun 15, 2020
1 parent ac200a1 commit 2421d44
Show file tree
Hide file tree
Showing 6 changed files with 500 additions and 40 deletions.
14 changes: 6 additions & 8 deletions openapi3/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ func (operation *Operation) AddResponse(status int, response *Response) {
responses = NewResponses()
operation.Responses = responses
}
if status == 0 {
responses["default"] = &ResponseRef{
Value: response,
}
} else {
responses[strconv.FormatInt(int64(status), 10)] = &ResponseRef{
Value: response,
}
code := "default"
if status != 0 {
code = strconv.FormatInt(int64(status), 10)
}
responses[code] = &ResponseRef{
Value: response,
}
}

Expand Down
7 changes: 6 additions & 1 deletion openapi3/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
type Responses map[string]*ResponseRef

func NewResponses() Responses {
return make(Responses, 8)
r := make(Responses)
r["default"] = &ResponseRef{Value: NewResponse().WithDescription("")}
return r
}

func (responses Responses) Default() *ResponseRef {
Expand All @@ -24,6 +26,9 @@ func (responses Responses) Get(status int) *ResponseRef {
}

func (responses Responses) Validate(c context.Context) error {
if len(responses) == 0 {
return errors.New("The Responses Object MUST contain at least one response code")
}
for _, v := range responses {
if err := v.Validate(c); err != nil {
return err
Expand Down
Loading

0 comments on commit 2421d44

Please sign in to comment.