@@ -84,7 +84,7 @@ func ToV3(doc2 *openapi2.T) (*openapi3.T, error) {
8484 if responses := doc2 .Responses ; len (responses ) != 0 {
8585 doc3 .Components .Responses = make (map [string ]* openapi3.ResponseRef , len (responses ))
8686 for k , response := range responses {
87- r , err := ToV3Response (response )
87+ r , err := ToV3Response (response , doc2 . Produces )
8888 if err != nil {
8989 return nil , err
9090 }
@@ -193,7 +193,7 @@ func ToV3Operation(doc2 *openapi2.T, components *openapi3.Components, pathItem *
193193 if responses := operation .Responses ; responses != nil {
194194 doc3Responses := make (openapi3.Responses , len (responses ))
195195 for k , response := range responses {
196- doc3 , err := ToV3Response (response )
196+ doc3 , err := ToV3Response (response , operation . Produces )
197197 if err != nil {
198198 return nil , err
199199 }
@@ -413,7 +413,7 @@ func onlyOneReqBodyParam(bodies []*openapi3.RequestBodyRef, formDataSchemas map[
413413 return nil , nil
414414}
415415
416- func ToV3Response (response * openapi2.Response ) (* openapi3.ResponseRef , error ) {
416+ func ToV3Response (response * openapi2.Response , produces [] string ) (* openapi3.ResponseRef , error ) {
417417 if ref := response .Ref ; ref != "" {
418418 return & openapi3.ResponseRef {Ref : ToV3Ref (ref )}, nil
419419 }
@@ -422,8 +422,18 @@ func ToV3Response(response *openapi2.Response) (*openapi3.ResponseRef, error) {
422422 Description : & response .Description ,
423423 ExtensionProps : response .ExtensionProps ,
424424 }
425+
426+ // Default to "application/json" if "produces" is not specified.
427+ if len (produces ) == 0 {
428+ produces = []string {"application/json" }
429+ }
430+
425431 if schemaRef := response .Schema ; schemaRef != nil {
426- result .WithJSONSchemaRef (ToV3SchemaRef (schemaRef ))
432+ schema := ToV3SchemaRef (schemaRef )
433+ result .Content = make (openapi3.Content , len (produces ))
434+ for _ , mime := range produces {
435+ result .Content [mime ] = openapi3 .NewMediaType ().WithSchemaRef (schema )
436+ }
427437 }
428438 if headers := response .Headers ; len (headers ) > 0 {
429439 result .Headers = ToV3Headers (headers )
0 commit comments