spring-boot - 当 api 定义在单独的接口上时,两次生成 Swagger
问题描述
我通过codegen生成了以下界面:
/**
* POST /pet : Add a new pet to the store
*
* @param petModel Pet object that needs to be added to the store (required)
* @return Invalid input (status code 405)
*/
@ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", tags={ "private", })
@ApiResponses(value = {
@ApiResponse(code = 405, message = "Invalid input") })
@RequestMapping(value = "/private/pet",
consumes = { "application/json" },
method = RequestMethod.POST)
default ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody PetModel petModel) throws Exception {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
然后我让我的控制器实现它:
public class PetController implements Api{
public ResponseEntity<Void> addPet(...
}
我还定义了这个案卷:
@Bean
public Docket myApi(ServletContext servletContext) {
return new Docket(DocumentationType.SWAGGER_2).pathProvider(new DefaultPathProvider() {
@Override
public String getOperationPath(String operationPath) {
return StringUtils.substringAfter(super.getOperationPath(operationPath),contextPath) ;
}
})
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build();
}
@Bean
public WebMvcConfigurer webMvcConfigurer()
{
return new WebMvcConfigurer()
{
@Override
public void addResourceHandlers( ResourceHandlerRegistry registry )
{
registry.addResourceHandler( "swagger-ui.html" ).addResourceLocations( "classpath:/META-INF/resources/" );
registry.addResourceHandler( "/webjars/**" ).addResourceLocations( "classpath:/META-INF/resources/webjars/" );
}
};
}
它可以工作,但是在产生的招摇中,我得到了一个与我的控制器相关的空行。我可以摆脱它吗?
解决方案
推荐阅读
- c# - 在 C# 中为数据库设置条件,确保列中的日期不应等于 html 表单中的选择
- python - VSCode 的 vscode-python 扩展是语言服务还是只是扩展?
- php - slim 框架中的 Container->get('route') 方法
- php - 带有消息“无效数据源名称”的未捕获异常“PDOException”
- c# - 如何让策略模式中的一种策略返回多个值
- javascript - Trumbowyg:Django 服务器可以检测文件上传但不能检测图像 URL 输入
- android - Android picasso 在加载到 imageView 之前检查图像 url 是否存在
- java - 如何将文件路径打印为超链接
- vba - VBA:ListObjects.DataBodyRange.ClearContents 在 2010 年不起作用
- pip - 无法使用 pip 在 OSX 上安装 lxml:550 无法更改目录