Cookie not sent in Headers with Swagger UI

3,661 views
Skip to first unread message

Francisco Pérez-Sorrosal

unread,
Apr 17, 2014, 10:31:20 AM4/17/14
to swagger-sw...@googlegroups.com
Hi!

I'm currently exercising my REST API with the Swagger UI and I have some problems with the header params for certain operations. 

For example this is a curl that is working on my API:

curl -v -X GET -H 'Content-Type: application/json' -H 'Cookie: Y=COOKIE_CONTENT_Y;T=COOKIE_CONTENT_T' http://{remote.host}:4080/v1/myResource1

However, when I exercise the API with Swagger UI it fails. The Swagger API for the method is configured like this:

    @GET
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @ApiOperation(value = "Get stuff", notes = "", response = MyResponse.class)
    @ApiResponses(value = { @ApiResponse(code = 200, message = "OK"),
            @ApiResponse(code = 500, message = "Internal Server Error."),
            @ApiResponse(code = 400, message = "Bad Request"), @ApiResponse(code = 401, message = "Unauthorized") })
    public Response getStuff(
            @ApiParam(value = "It should contain the Y and T Cookies", required = true) @HeaderParam(HttpHeaders.COOKIE) String cookie,
            @CookieParam("Y") String yCookie) throws BadRequestException, UnauthorizedException, InternalServerErrorException {

In the Swagger UI they appear tex-boxes to add the cookie params, however, when I execute the query, I can't see the Cookie sent on the request and it fails. This is the output I get from the Chrome dev tools:

Request URL:http://{remote.host}:4080/v1/myResource1
Request Method:GET
Status Code:401 Unauthorized
Request Headers
Accept:application/json
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,es;q=0.6
Connection:keep-alive
Host:{remote.host}:4080
Origin:null
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36
Response Headers
Access-Control-Allow-Headers:Content-Type, Cookie
Access-Control-Allow-Methods:GET, POST, DELETE, PUT, OPTIONS
Access-Control-Allow-Origin:*
Content-Length:52
Content-Type:application/json
Server:Jetty(9.1.3.v20140225)

I've seen that adding "supportHeaderParams: true," to the dist/index.html in the Swagger UI could help, but it doesn't work for me. Can you help me with this?

Thanks in advance!

Francisco

Francisco Pérez-Sorrosal

unread,
Apr 22, 2014, 9:11:47 AM4/22/14
to swagger-sw...@googlegroups.com
Hi! Any news on this? In this thread was described the same problem and you were able to reproduce the problem but apparently it's not working yet. Any news on this?
I checked out last version of Swagger UI but still had the same problem.

Thanks again,

Francisco

tony tam

unread,
Apr 29, 2014, 12:11:27 PM4/29/14
to swagger-sw...@googlegroups.com
Hi,
Can you please replace your swagger.js with version 2.0.30?  (see https://github.com/wordnik/swagger-js/blob/master/lib/swagger.js)

You can now add a cookie as follows:

window.authorizations.add("cookieSupport", new CookieAuthorization(new Cookie("a=1;domain=.test.com;path=/")));

I'd love to get some testing on this from folks, let me know how it goes

Danny Andrews

unread,
Jan 13, 2015, 3:05:05 PM1/13/15
to swagger-sw...@googlegroups.com
I tried this and I'm getting 'Uncaught ReferenceError: CookieJar is not defined'.

Looks like CookieJar is a dependency that isn't included in dist/lib? Or am I missing something?

Thanks!
Reply all
Reply to author
Forward
0 new messages