[英]Swagger showing not existing endpoints. How to get rid of them?
我正在使用这样的请求在Spring Boot中构建一个非常简单的REST服务:
但是当我转到localhost:8080 / swagger-ui.html时 ,我得到了一个很长的列表,其中没有现有的冗余端点,例如:
那么, 如何摆脱它们呢? 我找了一个答案,我只找到了如何将响应列表限制到特定路径,这不是我的问题。
我无法通过注释@ApiOperation(value =“xyz”,hidden = true)隐藏它们,因为我的Controller代码中不存在这些请求。
这是我的SwaggerConfig.java类:
@Configuration
@EnableSwagger2
class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.any())
.paths(regex("/api.*"))
.build();
}
}
顺便说一句,显然我在/ v2 / api-docs上遇到404错误,但我不认为这是我的问题,因为Swagger显示正确的端点列表,但也有很多不存在的端点。 虽然我没有找到404错误的解决方案,但我不知道我是否应该关心。
事实证明,我的Controller代码是问题所在:
//@RequestMapping("/resource/{id}")
@RequestMapping(value = "/resource/{id}", method = RequestMethod.GET)
必须在任何地方指定@RequestMapping中的方法才能在Swagger中获取正确的端点列表,即使REST服务工作正常而有时也没有指定。
是的,或者您使用@GetMapping(显然是用于GET方法)或@PostMapping用于POST,并且您不需要指定方法。 https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/GetMapping.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.