Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 543
VapeKop Avatar asked Sep 14 '25 18:09

VapeKop


1 Answers

Turns out, my Controller code was the problem:

 //@RequestMapping("/resource/{id}")
 @RequestMapping(value = "/resource/{id}", method = RequestMethod.GET)

Methods in @RequestMapping have to be specified everywhere to get the correct list of endpoints in Swagger, even though the REST service works fine without specifying those sometimes.

like image 192
VapeKop Avatar answered Sep 16 '25 08:09

VapeKop