Hi I am getting "The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers" error i.e Http 406 not acceptable.
I am using the below dependencies for swagger
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.8.4</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.3-M1</version>
</dependency>
My swagger config file is as below
@EnableSwagger2
@Component
public class SwaggerConfig {
@Bean
public Docket swaggerSpringMvcPlugin() {
ArrayList<ResponseMessage> standardExpectedHttpResponses =
createStandardExpectedHttpResponses();
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET,
standardExpectedHttpResponses)
.globalResponseMessage(RequestMethod.POST,
standardExpectedHttpResponses)
.globalResponseMessage(RequestMethod.PUT,
standardExpectedHttpResponses)
.globalResponseMessage(RequestMethod.DELETE,
standardExpectedHttpResponses)
/*.globalOperationParameters((List<Parameter>) new ParameterBuilder()
.name("xyz=id")
.description("Description of someGlobalParameter")
.modelRef(new ModelRef("string"))
.parameterType("query")
.required(true)
.build())*/
.produces(createStandardProducesConsumes())
.consumes(createStandardProducesConsumes()).pathMapping("")
.select()
.apis(RequestHandlerSelectors
.basePackage("com.x.y.z"))
.paths(PathSelectors.ant("/*"))
.build().apiInfo(metadata());
}
private ApiInfo metadata() {
return new ApiInfoBuilder()
.title("API - xyz")
.description(
"This is a Swagger-enabled API representation for the xyz.")
.version("1.0").build();
}
private ArrayList<ResponseMessage> createStandardExpectedHttpResponses() {
ArrayList<ResponseMessage> messages = new ArrayList<ResponseMessage>();
messages.add(new ResponseMessage(200, "Ok", null));
messages.add(new ResponseMessage(400, "Bad Request", null));
messages.add(new ResponseMessage(401, "Unauthorized", null));
messages.add(new ResponseMessage(403, "Forbidden", null));
messages.add(new ResponseMessage(404, "Not Found", null));
messages.add(new ResponseMessage(500, "Internal Server Error", null));
return messages;
}
private HashSet<String> createStandardProducesConsumes() {
HashSet<String> producesConsumes = new HashSet<String>();
producesConsumes.add("application/json");
return producesConsumes;
}
}
Also CORS filter is setup for the project. Anything is missing ? How do i resolve this.
When i hit the service it is giving me the response. It is working fine. I dont have to add any request parameters. Above link is giving me the response.
When I hit http://localhost:8080/endpoint/v2/api-docs, I have the http 406 error. Do i need to add any annotations to my service ?