swagger-ui
swagger-ui copied to clipboard
Response Body not shown when Content-Type in the response header is not set
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

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.

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

Hello, I would like to work on this one
@vibhuti019 sure, give it a try. Looking forward for a PR!
@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 if you are working on this you could consider checking the following:
- Json
- Xml
- Html
- Yaml(js-yaml dependency) Fallback: plain
@mathis-m ya sure
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*
Response Body: (Swagger and Postman)
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.