@@ -58,6 +58,7 @@ type OperationContext struct {
5858
5959 Output interface {}
6060 HTTPStatus int
61+ RespContentType string
6162 RespHeaderMapping map [string ]string
6263}
6364
@@ -345,7 +346,9 @@ func (r *Reflector) SetupResponse(oc OperationContext) error {
345346 resp := Response {}
346347
347348 if oc .Output != nil {
348- err := r .parseJSONResponse (& resp , oc .Output )
349+ oc .RespContentType = strings .Split (oc .RespContentType , ";" )[0 ]
350+
351+ err := r .parseJSONResponse (& resp , oc .Output , oc .RespContentType )
349352 if err != nil {
350353 return err
351354 }
@@ -354,6 +357,10 @@ func (r *Reflector) SetupResponse(oc OperationContext) error {
354357 if err != nil {
355358 return err
356359 }
360+
361+ if oc .RespContentType != "" {
362+ r .ensureResponseContentType (& resp , oc .RespContentType )
363+ }
357364 }
358365
359366 if resp .Description == "" {
@@ -367,7 +374,19 @@ func (r *Reflector) SetupResponse(oc OperationContext) error {
367374 return nil
368375}
369376
370- func (r * Reflector ) parseJSONResponse (resp * Response , output interface {}) error {
377+ func (r * Reflector ) ensureResponseContentType (resp * Response , contentType string ) {
378+ if _ , ok := resp .Content [contentType ]; ! ok {
379+ if resp .Content == nil {
380+ resp .Content = map [string ]MediaType {}
381+ }
382+
383+ resp .Content [contentType ] = MediaType {
384+ Schema : & SchemaOrRef {Schema : & Schema {}},
385+ }
386+ }
387+ }
388+
389+ func (r * Reflector ) parseJSONResponse (resp * Response , output interface {}, contentType string ) error {
371390 // Check if output structure exposes meaningful schema.
372391 if hasJSONBody , err := r .hasJSONBody (output ); err == nil && ! hasJSONBody {
373392 return nil
@@ -393,7 +412,11 @@ func (r *Reflector) parseJSONResponse(resp *Response, output interface{}) error
393412 resp .Content = map [string ]MediaType {}
394413 }
395414
396- resp .Content [mimeJSON ] = MediaType {
415+ if contentType == "" {
416+ contentType = mimeJSON
417+ }
418+
419+ resp .Content [contentType ] = MediaType {
397420 Schema : & oaiSchema ,
398421 Example : nil ,
399422 Examples : nil ,
0 commit comments