swagger-ui: Incorrect Accept header sent from Swagger-UI

I’ve got a java webapp where I’m doing version control via content negotiation. My method looks like:

@POST
@Consumes("application/vnd.mycompany.foo.v1+json")
@Produces("application/vnd.mycompany.bar.v1+json")
@ApiOperation(...)
@ApiResponses(...)
public Response createBar(
        @ApiParam(required = true) final Foo foo) {
    ..
}

On the UI, for Parameter Content Type, I select “vnd.mycompany.foo.v1+json”. When I [Try it out!], I get back a 406 Not Acceptable. These are the headers that go out:

Accept: application/json Content-Type: application/vnd.mycompany.foo.v1+json; charset=UTF-8

So it’s not surprising that I’m getting a 406, because my response type doesn’t match the accept header. I asked on the google group (https://groups.google.com/forum/#!topic/swagger-swaggersocket/NCQ3ZP7RV40), and was told I should report this as a bug.

I just grabbed the latest build from Download ZIP on the homepage and still see the issue.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 1
  • Comments: 21 (9 by maintainers)

Most upvoted comments

It hasn’t been resolved, but there’s a walkaround available - look through the forums here.

On Monday, August 17, 2015, teodora-yankova notifications@github.com wrote:

Hi, has the issue with Accept always being set to application/json been resolved? Thanks!

— Reply to this email directly or view it on GitHub https://github.com/swagger-api/swagger-ui/issues/485#issuecomment-131765230 .

Is there any info on which version the Accept header sending is still working?

I updated to the most recent versions (swagger-js 2.0.36, swagger-ui.js 2.0.21, swagger-jaxrs_2.10 1.3.7). I’m still having problems. Swagger-UI is now displaying

Response Body: no content
Response Code: 0
Response Headers: {}

I tried the query under firebug and I’m seeing this message in the console:

server can't produce application/json
swagger-ui.js (line 71)]

The headers appear to be going up correctly:

Accept  application/vnd.locustec.eim.query.secure.v1+json
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Length  123
Content-Type    application/vnd.locustec.eim.query.initial.v1+json; charset=UTF-8
DNT 1
Host    localhost:8080
Referer http://localhost:8080/eim-query/
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0

I see this in my Jersey log files:

14:31:46.898 [http-8080-4] DEBUG org.glassfish.jersey.tracing.general - FINISHED Response status: 200/SUCCESSFUL|OK [ ---- ms]
14:31:46.906 [http-8080-4] ERROR o.g.j.server.ServerRuntime$Responder - Error while closing the output stream in order to commit response.
java.lang.ArrayIndexOutOfBoundsException: null

When I use cURL to hit the url directly, I get a 200 and my expected data back.