Swagger showing not existing endpoints. How to get rid of them?

Viewed 2850

I'm building a really simple REST service in Spring Boot with requests like this:

  • GET /api/resources
  • POST /api/resources
  • GET /api/resources/id
  • DELETE /api/resources/id

But when I go to localhost:8080/swagger-ui.html, I get a really long list of not existing, redundant endpoints such as:

  • DELETE /api/resources
  • PATCH /api/resources
  • HEAD /api/resources
  • OPTIONS /api/resources
  • PATCH /api/resources/id
  • HEAD /api/resources/id
  • OPTIONS /api/resources/id

So, how to get rid of them? I've looked for an answer and I only found out how to limit the response list to a specific path, which is not my problem.

I can't hide them via annotation @ApiOperation(value = "xyz", hidden = true), since those requests don't exist in my Controller's code.

Here's my SwaggerConfig.java class:

@Configuration
@EnableSwagger2
class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(regex("/api.*"))
                .build();
    }
}

BTW, apparently I get an 404 error on /v2/api-docs, but I don't think that's my problem, since Swagger displays the correct list of endpoints, but also lots of not-existing ones. I haven't found the solution for this 404 error though, but I don't know if I should care.

2 Answers
Related