I'm trying to integrate swagger 2.0 with Spring Boot. Whenever I am going to hit to any Controller class API such as (POST,GET,DELETE,PUT). I am getting "Could not resolve reference because of: Could not resolve pointer: /definitions/Error does not exist in document " excption .
This is my Swagger configuration code.
SwaggerConfiguration.java
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.x.x.controller"))
.paths(PathSelectors.any()).build().useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, errorList())
.globalResponseMessage(RequestMethod.POST, errorList())
.globalResponseMessage(RequestMethod.PUT, errorList())
.globalResponseMessage(RequestMethod.DELETE, errorList());
}
private List<ResponseMessage> errorList() {
List<ResponseMessage> errorList = new ArrayList<ResponseMessage>();
errorList.add(new ResponseMessageBuilder().code(400).message("Some error message")
.responseModel(new ModelRef("Error")).build());
errorList.add(new ResponseMessageBuilder().code(401).message("Some error message")
.responseModel(new ModelRef("Error")).build());
errorList.add(new ResponseMessageBuilder().code(404).message("Some error message")
.responseModel(new ModelRef("Error")).build());
return errorList;
}
}
Thank you.