diff --git a/_examples/advanced-generic/_testdata/openapi.json b/_examples/advanced-generic/_testdata/openapi.json index 8faaad0..250f48d 100644 --- a/_examples/advanced-generic/_testdata/openapi.json +++ b/_examples/advanced-generic/_testdata/openapi.json @@ -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"}}} diff --git a/openapi/collector.go b/openapi/collector.go index 2006fd0..3070c88 100644 --- a/openapi/collector.go +++ b/openapi/collector.go @@ -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) } @@ -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) } @@ -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]