swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

Server returned HTTP response code: 406 for URL: .../api-docs/

Open daivanov opened this issue 11 years ago • 6 comments

I'm using Swagger 1.0 in my project and after switching to develop_2.0 branch in swagger-codegen I'm getting 406 not accepted message from my application, when I try to build a documentation

$ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i http://localhost:8080/MWA/api-docs/ -l html -o xxx reading from http://localhost:8080/MWA/api-docs/ java.io.IOException: Server returned HTTP response code: 406 for URL: http://localhost:8080/MWA/api-docs/

Master seems to send the following accept header:

Accept: text/html, image/gif, image/jpeg, ; q=.2, */; q=.2

And develop_2.0 sends:

Accept: application/json, application/yaml, .

daivanov avatar May 05 '15 17:05 daivanov

@daivanov, perhaps your url is not correct, on develop_2.0 it should look like yourUrlPattern/swagger.json but not MWA/api-docs/ (e.g http://petstore.swagger.io/v2/swagger.json). Could you check this?

lugaru1234 avatar May 20 '15 12:05 lugaru1234

I'm using swagger 1.0 on server side and swagger-codegen should be using compatibility converter to access old URL, because new URL doesn't exist on my server.

daivanov avatar May 20 '15 13:05 daivanov

@webron, Accepted media types are set in swagger-parser https://github.com/swagger-api/swagger-parser/blob/develop/modules/swagger-parser/src/main/java/io/swagger/parser/util/RemoteUrl.java#L84. And I'm not sure what . means. If all media types is implied it should be /. And I'm not sure all media types are suitable here. What's your opinion?

lugaru1234 avatar May 20 '15 15:05 lugaru1234

@lugaru1234 - I don't really follow your question..

webron avatar May 20 '15 15:05 webron

@webron, As you can see from https://github.com/swagger-api/swagger-parser/blob/develop/modules/swagger-parser/src/main/java/io/swagger/parser/util/RemoteUrl.java#L84 we append '.' to the accept header according to tne RFC http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html '.' is not valid, so the server may send a 406:

If an Accept header field is present, and if the server cannot send a response which is acceptable according to the combined Accept field value, then the server SHOULD send a 406 (not acceptable) response.

lugaru1234 avatar May 21 '15 08:05 lugaru1234

Right, it looks like the intent was to send */*and not *.*.

webron avatar May 21 '15 15:05 webron