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.
Hi, this was broken. It has been fixed in swagger-js 2.0.34, and swagger-ui 2.0.19. Please try that out, and reopen if you see an issue.
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.
@fehguy - is it possible this modification also changed swagger-ui to not assume application/json if there's no mention of consumes by default? See #518
Is there any info on which version the Accept header sending is still working?
Have you tried master? I know of no open issues for content negotiation on it
On Aug 19, 2014, at 8:04 AM, "Martin Dürrmeier" [email protected] wrote:
Is there any info on which version the Accept header sending is still working?
—
Reply to this email directly or view it on GitHub.
please use swagger-js 2.0.38 and reopen if you're having issues still.
https://raw.githubusercontent.com/wordnik/swagger-js/master/lib/swagger.js
Seems the issue is back in :
// swagger-ui.js
// version 2.1.0-alpha.7
@okigan - can you give more information about your use case? in my test it seems to work fine.
Ok found the issue:
@Produces({MediaType.APPLICATION_JSON, PROJECT_MODEL_JSON})
@ApiOperation(value = "Query projects")
public Iterable<Long> query
But this works:
@Produces({MediaType.APPLICATION_JSON, PROJECT_MODEL_JSON})
@ApiOperation(value = "Query projects", response = Long.class, responseContainer = "List")
public Iterable<Long> query
Would be nice if UI would show response model as list of Longs:

And just occurred to me, the model is different based on accept type, is that possible to specify that ?
That's not really related to the Accept header.
As for describing different models per content-type, it is currently not possible. You can follow this issue - https://github.com/swagger-api/swagger-spec/issues/146.
I bumped into the same problem. Swagger-ui keeps setting the Accept:application/json.
Simple POST request with consumes: application/x-www-form-urlencoded and produces: "application/xml; charset=UTF-8".
I have tried swagger-ui-2.0.19, 2.1.0-M2.
What am I doing wrong? Is there any place in code where I can override this?
@ivan-golubev - can you share your Swagger definition?
OK, here is the swagger.json :
{
"swagger": "2.0",
"info": {
"description": "This is a sample documentation.",
"version": "1.0.0",
"title": "documentation",
"contact": {
"email": "[email protected]"
}
},
"host": "localhost:8080",
"basePath": "/",
"schemes": [
"http"
],
"paths": {
"/users": {
"post": {
"summary": "Create profile",
"description": "Authenticate user with either Facebook id and create a new profile for him.",
"operationId": "createProfile",
"consumes": [
"application/x-www-form-urlencoded"
],
"produces": [
"application/xml; charset=UTF-8"
],
"parameters": [
{
"in": "header",
"name": "auth_method",
"description": "facebook",
"default": "facebook",
"required": true,
"type": "string"
},
{
"in": "formData",
"name": "application",
"description": "none",
"required": true,
"default": "facebook",
"type": "string"
}
],
"responses": {
"405": {
"description": "Invalid input"
}
}
}
}
}
}
@ivan-golubev - there indeed seems to be an issue there. Can you please open a new ticket with the details?
It hasn't been resolved, but there's a walkaround available - look through
the forums here.
On Monday, August 17, 2015, teodora-yankova [email protected]
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
.
I having same problem: I am requesting DELETE with formData, which is requested not as api requires (MediaType.APPLICATION_FORM_URLENCODED) but UI requests MediaType.APPLICATION_JSON. This is completely wrong
Verified working in master
Hi @fehguy, is it new SWAGGER-UI ? and also my DELETE problem mentioned above working ? thx
Yes I have just confirmed. Please try and post back.
Actually the workaround for this to include the response value like -
@ApiOperation(value = "Query projects", response = Long.class, responseContainer = "List")
then the swagger will display the Response content type
I am having this same issue and have been trying to resolve it from last 24 hours. Even though I specifically mentioned "consumes:["application/xml"]" still the requests go as "Accept: Application/json". Our API endpoint returns an XML response back and because of this I am getting a 0 response code and no content - response body. Our configuration is Swagger 2.0
Most helpful comment
It hasn't been resolved, but there's a walkaround available - look through
the forums here.
On Monday, August 17, 2015, teodora-yankova [email protected]
wrote: