@@ -84,7 +84,7 @@ func ToV3(doc2 *openapi2.T) (*openapi3.T, error) {
84
84
if responses := doc2 .Responses ; len (responses ) != 0 {
85
85
doc3 .Components .Responses = make (map [string ]* openapi3.ResponseRef , len (responses ))
86
86
for k , response := range responses {
87
- r , err := ToV3Response (response )
87
+ r , err := ToV3Response (response , doc2 . Produces )
88
88
if err != nil {
89
89
return nil , err
90
90
}
@@ -193,7 +193,7 @@ func ToV3Operation(doc2 *openapi2.T, components *openapi3.Components, pathItem *
193
193
if responses := operation .Responses ; responses != nil {
194
194
doc3Responses := make (openapi3.Responses , len (responses ))
195
195
for k , response := range responses {
196
- doc3 , err := ToV3Response (response )
196
+ doc3 , err := ToV3Response (response , operation . Produces )
197
197
if err != nil {
198
198
return nil , err
199
199
}
@@ -413,7 +413,7 @@ func onlyOneReqBodyParam(bodies []*openapi3.RequestBodyRef, formDataSchemas map[
413
413
return nil , nil
414
414
}
415
415
416
- func ToV3Response (response * openapi2.Response ) (* openapi3.ResponseRef , error ) {
416
+ func ToV3Response (response * openapi2.Response , produces [] string ) (* openapi3.ResponseRef , error ) {
417
417
if ref := response .Ref ; ref != "" {
418
418
return & openapi3.ResponseRef {Ref : ToV3Ref (ref )}, nil
419
419
}
@@ -422,8 +422,18 @@ func ToV3Response(response *openapi2.Response) (*openapi3.ResponseRef, error) {
422
422
Description : & response .Description ,
423
423
ExtensionProps : response .ExtensionProps ,
424
424
}
425
+
426
+ // Default to "application/json" if "produces" is not specified.
427
+ if len (produces ) == 0 {
428
+ produces = []string {"application/json" }
429
+ }
430
+
425
431
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
+ }
427
437
}
428
438
if headers := response .Headers ; len (headers ) > 0 {
429
439
result .Headers = ToV3Headers (headers )
0 commit comments