Skip to content

Commit

Permalink
Remove body from schema of 1xx, 204, 304 responses (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Mar 9, 2023
1 parent 05afe69 commit f130620
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 1 addition & 4 deletions _examples/advanced-generic/_testdata/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,7 @@
},
"content":{"text/csv":{"schema":{"type":"string"}}}
},
"304":{
"description":"Not Modified",
"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdvancedCustomErr"}}}
},
"304":{"description":"Not Modified"},
"500":{
"description":"Internal Server Error",
"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AdvancedCustomErr"}}}
Expand Down
13 changes: 12 additions & 1 deletion openapi/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,10 @@ func (c *Collector) setJSONResponse(op *openapi3.Operation, output interface{},
oc.Operation = op
oc.Output = output
oc.HTTPStatus = statusCode
oc.RespContentType = c.DefaultErrorResponseContentType

if output != nil {
oc.RespContentType = c.DefaultErrorResponseContentType
}

return c.Reflector().SetupResponse(oc)
}
Expand Down Expand Up @@ -295,6 +298,10 @@ func (c *Collector) processExpectedErrors(op *openapi3.Operation, u usecase.Inte
statusCode, errResp = rest.Err(e)
}

if statusCode < http.StatusOK || statusCode == http.StatusNotModified || statusCode == http.StatusNoContent {
errResp = nil
}

if errsByCode[statusCode] == nil {
statusCodes = append(statusCodes, statusCode)
}
Expand All @@ -306,6 +313,10 @@ func (c *Collector) processExpectedErrors(op *openapi3.Operation, u usecase.Inte
}
}

return c.combineErrors(op, statusCodes, errsByCode)
}

func (c *Collector) combineErrors(op *openapi3.Operation, statusCodes []int, errsByCode map[int][]interface{}) error {
for _, statusCode := range statusCodes {
var (
errResps = errsByCode[statusCode]
Expand Down

0 comments on commit f130620

Please sign in to comment.