Swagger 2.0 Could not resolve reference because of: Could not resolve pointer
Asked Answered
S

0

7

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;
}

}

Error Image

Thank you.

Swagger Block

Saprophagous answered 3/12, 2018 at 11:38 Comment(2)
Possible duplicate of Getting error while loading swagger-ui.html in spring(5.0.0.RELEASE) mvcFatma
Hey Thanks @Fatma for reply. It is working fine. but there 2 sections or blocks are displaying which look ugly, such as one for "string" another for "message" . Is there a way to make them in single block. I just added the image , please take a look once.Saprophagous

© 2022 - 2024 — McMap. All rights reserved.