I'm building a really simple REST service in Spring Boot with requests like this:
But when I go to localhost:8080/swagger-ui.html, I get a really long list of not existing, redundant endpoints such as:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With