Swagger UI not displaying all response headers

3,681 views
Skip to first unread message

Dan Sellars

unread,
Jun 19, 2014, 2:23:47 PM6/19/14
to swagger-sw...@googlegroups.com
Hello,

I am just getting started with Swagger and I am having a little issue.

I have the latest code from git that I rebuild myself following the instructions in the readme, apart from installing handlebars. I could not see how to as it is only a js file to download and it did not seem to complain anyway when I ran the build.

My server is a JAX-RS application running on glassfish, as I am running on different servers I had to set up CORS which now seems to be working well. With the swagger ui app I can see the API I have annotated and it mostly seems good.

The problem I ham having is as follows:

When I am looking at the the response to a POST, sent to my server from Swagger UI, I am getting the response code I expect and my server is behaving as expected but I am only seeing one header in the in the "Response Headers" section. As follows:

{
"Content-Type": "application/json;charset=UTF-8"
}

The server is setting the location header to the url of the newly created entity but this is not showing up. I independently verified that the server response contains this header byt using the python requests library and I get a response some what like:

{'content-length': '0', 'access-control-allow-headers': 'Content-Type', 'x-powered-by': 'Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)', 'server': 'GlassFish Server Open Source Edition 3.1.2.2', 'location': '<URL to new entity>', 'date': 'Thu, 19 Jun 2014 17:27:09 GMT', 'access-control-allow-origin': '*', 'access-control-allow-methods': 'GET, POST, DELETE, PUT', 'content-type': 'application/json;charset=UTF-8'}

Could you help me shed any light on why this would be?

Cheers,
Dan.

Ron

unread,
Jun 19, 2014, 2:47:31 PM6/19/14
to swagger-sw...@googlegroups.com
Can you try the pre-built Swagger-UI? It's located in the /dist directory of the repo.


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Sellars

unread,
Jun 19, 2014, 2:55:39 PM6/19/14
to swagger-sw...@googlegroups.com
Hi, Thanks for the quick response.

I just tried that as you requested, cloned the repo again and just copied over the dist dir to my webserver.

I get exactly the same result as before.

Cheers,
Dan.

Ron

unread,
Jun 19, 2014, 2:59:30 PM6/19/14
to swagger-sw...@googlegroups.com
Okay, can you check with the developer tools in your browser to see what the actual response that you're getting?


Dan Sellars

unread,
Jun 19, 2014, 3:27:34 PM6/19/14
to swagger-sw...@googlegroups.com
Using the Firebug console I saw the following headers in the response (I just redacted the actual URL):

Access-Control-Allow-Head...Content-Type
Access-Control-Allow-Meth... GET, POST, DELETE, PUT
Access-Control-Allow-Orig...*
Content-Length0
Content-Typeapplication/json;charset=UTF-8
DateThu, 19 Jun 2014 19:23:38 GMT
Location<expected URL>
Server
GlassFish Server Open Source Edition 3.1.2.2
X-Powered-By
Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)


Does that help?
Cheers,


--
You received this message because you are subscribed to a topic in the Google Groups "Swagger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swagger-swaggersocket/TD0MWY09ESo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to swagger-swaggers...@googlegroups.com.

Ron

unread,
Jun 19, 2014, 3:31:33 PM6/19/14
to swagger-sw...@googlegroups.com
Just to be sure, that's what you see when you click the 'Try it out' button in Swagger-UI?

Dan Sellars

unread,
Jun 19, 2014, 3:48:39 PM6/19/14
to swagger-sw...@googlegroups.com
Yes, the following is the process I followed.

I am looking at the repo version of the swagger ui, running on the built in apache of a mac.

1. Add my server url to the green swagger bar, hit enter.
2. My api appears below
3. Browse to the POST method I am using, add model schema from the Data Type and fill in values (really cool!)
4. Bring up Firebug console and enable  'all' the clear it.
5. Click "Try it out!"
6. Response appears on the webpage and headers only contain:

Response Headers

{
"Content-Type": "application/json;charset=UTF-8"
}

7. Look on Firebug console and see the POST to my REST service has appeared, expand it.
8. Response headers contain:
Access-Control-Allow-Head...Content-Type
Access-Control-Allow-Meth...GET, POST, DELETE, PUT
Access-Control-Allow-Orig...*
Content-Length0
Content-Typeapplication/json;charset=UTF-8
DateThu, 19 Jun 2014 19:42:30 GMT
Location<correct url>
ServerGlassFish Server Open Source Edition 3.1.2.2
X-Powered-ByServlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)

Ron

unread,
Jun 19, 2014, 3:56:32 PM6/19/14
to swagger-sw...@googlegroups.com
Okay, there seems to be an actual issue here.

If you take a look at http://petstore.swagger.wordnik.com/ - it has an older version of swagger-ui and if you try it out (you can point it to your url), you'll see the full headers.

I pulled the latest swagger-ui and noticed what you're seeing as well.
There have been a few pull requests regarding the response headers (https://github.com/wordnik/swagger-ui/pull/479 and https://github.com/wordnik/swagger-ui/pull/478) which were merged yesterday.
I don't know if those are related to the issue or not.

Can you please open an issue and describe what you're doing (expected results, what really happens)?

Also, just for future reference, when running swagger-ui locally, you don't need to host it. Just open the index.html directly in your favorite browser and run with it.


Dan Sellars

unread,
Jun 19, 2014, 4:10:06 PM6/19/14
to swagger-sw...@googlegroups.com
Hi

I managed to figure out what is happening. I needed to add another CORS header to be able to see it. I am not sure it is really an issue with swagger, but CORS is new to me so I am not sure.

I read this https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS and then tried adding:

res.addHeader("Access-Control-Expose-Headers", "Location");

to my servlet filter that adds the extra headers on and it now shows up in the response header section:

{
"Location": "http://<correct URL>",
"Content-Type": "application/json;charset=UTF-8"
}

For reference this is how I am setting up my CORS stuff on glassfish now:

public class HTML5CorsFilter implements javax.servlet.Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse res = (HttpServletResponse) response;
        res.addHeader("Access-Control-Allow-Origin", "*");
        res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
        res.addHeader("Access-Control-Allow-Headers", "Content-Type");
        res.addHeader("Access-Control-Expose-Headers", "Location");
        chain.doFilter(request, response);
    }
    ...


If you still think there is an issue here let me know and I can create one for you.

Thank you very much for your help, with out you asking be to do all of that I would not have realised what was going on.

Also thanks for the note about running locally.

Regards,
Dan.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Ron

unread,
Jun 19, 2014, 4:20:16 PM6/19/14
to swagger-sw...@googlegroups.com
This may be the result of the recent change, I honestly don't know. I'm not really that involved with Swagger-UI and my experience with CORS is limited.
This is an interesting find (at least for me) and it would help in supporting future related issues, so thank you for that.

I'll update the CORS tutorial we have on the matter as well.


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages