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

Showing 'no content' in response body

Open arunbabucode opened this issue 9 years ago • 13 comments

Hi Team,

First of all, this isn't an issue for sure, but I tried almost a day with no success. It will be great if someone can suggest what am doing wrong.

Swagger UI version => 2.2.6

Problem - Whenever am trying to use the try now button, swagger shows me no content in the response body, response code '0' and response header as '"error": "no response from server"'. However, in chrome developer tools, the correct request is going and the expected response is showing.

Note:

  • My application and swagger UI is on the same host, same port, So I don't think there is a CORS issue
  • Tried the same request using swagger generated curl request, returned expected response.
  • Tried the request on Postman, got expected response.

arunbabucode avatar Dec 26 '16 07:12 arunbabucode

The error is real, but misleading. In most likelihood, you've set the spec so that it returns a specific content type (say, application/json) but you actually return plain text (like a string or a number). swagger-ui expects it to be a JSON, tries to parse it and fails, giving you the wrong error message. However, it does mean your spec does not match what your API actually does.

webron avatar Dec 26 '16 17:12 webron

This should no longer be an issue with the new UI.

webron avatar Jun 10 '17 04:06 webron

If you are using .NET Core. Using this in startup.cs file

services .AddMvc() .AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

bijayy33 avatar Oct 21 '17 07:10 bijayy33

Hi Team, I am facing same issue. I am using Swagger 2.7.0. When I return "String" from the REST api, swagger-ui is displaying "no content" in the response body with response code as "0". I knew that swagger is not able to parse String to JSON. I have tried giving "text/plain" in swagger java file as producer, but no luck. How can I fix this.

Arun8460 avatar Nov 09 '17 11:11 Arun8460

There's no such thing as 'Swagger 2.7.0'.

webron avatar Nov 09 '17 17:11 webron

"2.7.0" is the Springfox library version not the Swagger version. Following is the dependency used. io.springfox springfox-swagger2 2.7.0 io.springfox springfox-swagger-ui 2.7.0

When I return "String" from the REST api, swagger-ui is displaying "no content" in the response body with response code as "0". I knew that swagger is not able to parse String to JSON. I have tried giving "text/plain" in swagger java file as producer, but no luck. How can I fix this.

Arun8460 avatar Nov 13 '17 06:11 Arun8460

I don't know what version of swagger-ui is provided with springfox 2.7.0.

webron avatar Nov 13 '17 22:11 webron

On hitting http://xxxxxxxxxx:xxxx/rw/user/v2/api-docs, I got api-docs, swagger version is 2.0 as per the following info:

{"swagger":"2.0","info":{"description":"Api Documentation","version":"1.0","title":"Api Documentation","termsOfService":"urn:tos","contact":{},"license":{"name":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0"}},"host":"xxxxxxxxxxx}

Springfox 2.7.0 is mapped with Swagger 2.0 (from the above api-docs info). How can I limit the issue.

Arun8460 avatar Nov 14 '17 07:11 Arun8460

@webron , is there any update on this?

Arun8460 avatar Nov 23 '17 13:11 Arun8460

Following info is from springfox-swagger-ui-2.7.0.jar: Manifest-Version: 1.0 Build-Time: 2017-05-20T22:12:34-0500 Built-With: gradle-3.5, groovy-2.4.10 Implementation-Title: springfox-swagger-ui Implementation-Version: 2.7.0 Built-On: ISDV161716L.local/192.168.1.163 Built-By: d_krishnan Created-By: 1.7.0_79 (Oracle Corporation) SwaggerUi-Version: 2.2.10

Is there a way to upgrade swagger-ui version to limit the issue?

Arun8460 avatar Nov 24 '17 06:11 Arun8460

I am using swagger on the same localhost server as where the web services are located and had the same problem. So no CORS problem could be involved. I also tried @bijayy33 suggestion, but it did not bring any improvement.

I then investigated the content of the web service response in Fiddler, and found that some characters were put before and after the response's payload. The payload was supposed to be:

{ error: "The method or operation is not implemented." }

But what Fiddler showed was:

38
{ error: "The method or operation is not implemented." }
0

I had to make sure to call

context.Response.Clear();

before calling

context.Response.WriteAsync([...]);

to clear any content that could have already been written in the response before writing my own response.

I have no idea why some characters were there before and after my payload. I am pretty new with swagger and .NET Core. If someone can tell the reason.

I hope it helps!

sboisse avatar Feb 21 '18 22:02 sboisse

I had same issue, howerever it was releated to the invalid JSON formatting of the response. One string value had "enter" - new line appened to it. Correcting this solved the issue.

shindmay avatar Sep 09 '24 12:09 shindmay

I'm exposing a server-streaming gRPC endpoint via grpc-gateway, which returns NDJSON over HTTP.

Endpoint works correctly via: curl and direct HTTP clients But Swagger UI shows empty / no response

varunbv1 avatar Apr 07 '26 11:04 varunbv1