I'm attempting to use springfox 2.6.1 (springfox-swagger2 and springfox-swagger-ui) with a Spring MVC application to generate swagger docs. My application has many existing REST api's however I only want to swaggerize one of them at the moment. It resembles the following:
@RestController
public class MyController {
@RequestMapping(value = "/getapi/{key}", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "get something", response = MyEntity.class)
@ApiResponse(code = 404, message = "Not found")
public ResponseEntity<String> find(@ApiParam(value = "", required = true) @PathVariable String key) {
...
}
I've followed a couple of examples to help me get started:
- http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api
- A 'simple' way to implement Swagger in a Spring MVC application
After starting the application and navigating to http://host/my-app/swagger-ui.html
I see the docs for my REST controller, however under the list of operations is every possible http method. That is a GET, POST, PUT, DELETE, etc for the same REST endpoint. I would expect to see only a GET operation. Below is my bean configuration. Is something missing or misconfigured?
@Configuration
@EnableSwagger2
public class Config{
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.build()
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("My API").version("v1").build();
}
}