将swagger-maven-plugin集成到Spring应用程序中

时间:2015-08-04 11:08:16

标签: spring swagger

我正在努力将Swagger合并到我的Spring应用程序中。我正在尝试使用.jsoncom.github.kongchen:swagger-maven-plugin:3.1.0生成io.swagger:swagger-core:1.5.0文件进行注释,但生成的文件完全为空:

{
  "swagger" : "2.0",
  "info" : {
    "version" : "v1",
    "title" : "KVS"
  }
}

控制器示例

@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注释得到一些结果(不太正确,我会说),但这会适得其反。我可能做错了什么?

1 个答案:

答案 0 :(得分:1)

请在此repo上使用Spring MVC注释检查工作插件的简单示例:

https://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

插件对依赖项版本以及是否存在特定注释很敏感。