swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Response Body not shown when Content-Type in the response header is not set

Open vinaylondhe-highspot opened this issue 5 years ago • 6 comments

Q&A (please complete the following information)

  • OS: macOS
  • Browser: chrome
  • Method of installation: dist
  • Swagger-UI version: 3.26.2
  • Swagger/OpenAPI version: OpenAPI 3.0

Describe the bug you're encountering

When the Content-Type response header is not set, swagger-ui does not show the Response Body. I am seeing this issue when using OpenAPI 3.0 with swagger-ui 3.26.2 Screen Shot 2020-06-15 at 5 41 59 PM

When using Swagger 2.0 with swagger-ui 2.2.10, we do see Response Body even when the Content-Type response header is not set. Screen Shot 2020-06-15 at 5 44 32 PM

As you can see in the above picture, the Content-Type is set to null

So I am wondering if there is any way for swagger-ui(3.26.2) to show the Response Body even when the Content-Type response header is not set

Additional context or thoughts

I can confirm that if I pass in the Content-Type response header, the Response Body is seen like below

Screen Shot 2020-06-15 at 5 53 08 PM

vinaylondhe-highspot avatar Jun 16 '20 00:06 vinaylondhe-highspot

Hello, I would like to work on this one

vibhuti019 avatar Oct 09 '21 21:10 vibhuti019

@vibhuti019 sure, give it a try. Looking forward for a PR!

char0n avatar Oct 11 '21 11:10 char0n

@char0n I am using a very basic fix: Firstly, I will try to JSON parse the response body. If there is no error then the program will render the response as JSON. Then I will try to parse the data as XML.. and lastly, XML gets an error, the output will be rendered as HTML text (i.e <,> to <,> ).

vibhuti019 avatar Oct 16 '21 12:10 vibhuti019

@vibhuti019 if you are working on this you could consider checking the following:

  1. Json
  2. Xml
  3. Html
  4. Yaml(js-yaml dependency) Fallback: plain

mathis-m avatar Oct 16 '21 20:10 mathis-m

@mathis-m ya sure

vibhuti019 avatar Oct 18 '21 19:10 vibhuti019

Not exactly sure if this may help, but it's worth a shot:

I was noticing the same sort of error when I was playing with my app and using swagger ui and Postman, and neither were returning the response, while another resource was. The GET method in question was identical to the working example minus the domain/entity object it returns. I took a few hours to determine the exact cause (embarrassing lol).

No Response Body: (Swagger and Postman) NOTE: I removed the AUTH token for all screenshots if in plain text* Swagger Not Working Empty 200 body

Response Body: (Swagger and Postman) Swagger Working Populated 200 Body

Fix: I had edited some of my domain objects or entity objects to implement Comparable<Domain/Entity Class> but not the one in question. Not sure how long this had been going on, but after checking the working example to the nonworking example, I finally discovered the interface was the only thing missing (since my GET method for the working resource to the nonworking resource were identical minus the domain/entity class they were returning). After adding the compareTo() method, the Response body started showing up. I hope this helps, and if not, my only advice is to look at another working example, and compare it to the nonworking example. Something about the related files must be different.

aaronhunter1088 avatar Jun 14 '24 02:06 aaronhunter1088