Request being performed but response data not updated on Swagger UI

1,521 views
Skip to first unread message

Ariel Kogan

unread,
May 21, 2013, 5:55:57 AM5/21/13
to swagger-sw...@googlegroups.com
Hello,

I'm running Swagger on localhost:80 and my API documentation on localhost:38080. I've set the CORS headers and I don't get any errors about that in Chrome nor Firefox consoles.

However, when I make a request to an API, the Swagger UI won't show me the response body, code nor headers.

From the console, I see that the browser makes an OPTIONS request to the API's URL and then a GET (which is the method I want to invoke). I see that the GET returns a 200 but the Swagger UI doesn't reflect it. My Firefox console shows the following:

[10:54:09.896] OPTIONS http://localhost:38080/api/foo/123 [HTTP/1.1 200 OK 4ms]
[10:54:09.897] GET http://localhost:38080/api/foo/123 [HTTP/1.1 200 OK 47ms]
[10:54:09.840] bodyParam = null
[10:54:09.840] submitting http://localhost:38080/api/foo/123
[10:54:09.841] content type = application/json
[10:54:09.841] content type is now = false

Do someone have any hint about what could be happening here?

Many thanks,


Ariel

Ariel Kogan

unread,
May 21, 2013, 6:29:35 AM5/21/13
to swagger-sw...@googlegroups.com
Update:

It does work on Firefox but not on Chrome. Chrome's console reads:

XMLHttpRequest cannot load http://localhost:38080/api/foo/123. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

I've tried to set the Access-Control-Allow-Origin to *, localhost, localhost:38080, http://localhost, http://localhost:38080 with no luck.

tony tam

unread,
May 21, 2013, 10:37:00 AM5/21/13
to swagger-sw...@googlegroups.com
What server framework are you using?  How did you set the access-control-allow-origin?

Ariel Kogan

unread,
May 21, 2013, 11:01:46 AM5/21/13
to swagger-sw...@googlegroups.com
I'm using Spray Routing and my response headers look as follows:

Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: api_key, Content-Type
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT
Access-Control-Allow-Credentials: true

tony tam

unread,
May 22, 2013, 1:07:33 PM5/22/13
to swagger-sw...@googlegroups.com
That looks correct, but the chrome console message tells me that something isn't getting back correctly from the server.  Can you try this:


And see what headers you get back?

Ariel Kogan

unread,
May 23, 2013, 6:02:30 AM5/23/13
to swagger-sw...@googlegroups.com
Thank you for the reply Tony.

I've run the curl, please find it below.
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
ccess-Control-Allow-Headers: api_key, Content-Type
Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT
Access-Control-Allow-Credentials: true
Content-Type: application/json; charset=UTF-8
Content-Length: 11592
Server: Jetty(8.1.7.v20120910)
Proxy-Connection: keep-alive
Connection: keep-alive

{ JSON response payload }

tony tam

unread,
May 23, 2013, 12:29:14 PM5/23/13
to swagger-sw...@googlegroups.com
If you're using Spray, I have to guess that you've manually created the json spec files--if so, maybe you can share them?  I'm not seeing any issue with what you're describing.

Ariel Kogan

unread,
May 24, 2013, 10:40:23 AM5/24/13
to swagger-sw...@googlegroups.com
Hello.
In a very odd way, it's working now. I basically enabled the OPTIONS method to every route (every resource) in my service and now the Swagger UI works on Chrome.
Will try to pinpoint what happened before.
Thanks for the help.
Reply all
Reply to author
Forward
0 new messages