我很难尝试将 Swagger 合并到我的 Spring 应用程序中。我试图生成 .json
文件使用 com.github.kongchen:swagger-maven-plugin:3.1.0
和io.swagger:swagger-core:1.5.0
用于注释,但生成的文件完全是空的:
{
"swagger" : "2.0",
"info" : {
"version" : "v1",
"title" : "KVS"
}
}
Controller 示例
@RestController
@Api(
tags = { "k/v" },
value = "Main microservice entrypoint",
produces = "application/json",
consumes = "application/json",
protocols = "http,https"
)
class AbcController {
@ApiOperation(value = "/")
@ApiResponses({
@ApiResponse(code = 200, message = "Request entry", response = KvsEntry.class),
@ApiResponse(code = 404, message = "Entry not found", response = Void.class)
})
@RequestMapping(value = "/", method = RequestMethod.POST)
public ResponseEntity<KvsEntry> create(@Validated @RequestBody KvsEntry kvsEntry) {
kvsEntry = keyValueService.saveEntry(kvsEntry);
return new ResponseEntity<>(kvsEntry, HttpStatus.OK);
}
}
我仍然可以使用 <springmvc>false</springmvc>
获得一些结果配置和 JAX-RS 注释(我想说,不太正确),但这会适得其反。我可能做错了什么?
最佳答案
请检查此存储库上带有 Spring MVC 注释的工作插件的简单示例:
https://github.com/khipis/swagger-maven-example
插件对依赖项版本以及是否存在特定注释很敏感。
关于spring - 将 swagger-maven-plugin 集成到 Spring 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31807676/