8

I am looking for a way to generate documentation for my Rest API's that were created using the Jersey framework.

Are there any tools to generate such documentation? Also, what are the best practices for documenting Rest API's.

4

2 回答 2

6

几个月前我对此进行了一些研究,我的结论是记录 Jersey(以及许多其他人!)REST API 的最佳框架是“Swagger” - http://swagger.io/。它是一个开源项目(https://github.com/swagger-api/swagger-core),使用/集成非常简单。您只需向 REST API 添加一些注释,它就会生成一个包含所有 API 资源、请求/响应消息的“网站”,甚至允许直接从那里执行测试。以下是 API 资源的文档示例:

@POST
@Produces("application/json")
@Consumes({ "application/xml", "application/json"})
@ApiOperation(
    value = "Short description of resources",
    notes = "Detailed textual description of the resource...",
    responseClass = "com.example.data.resps.PostExampleResp")
@ApiErrors(value = { @ApiError(code = 404, reason = "Resources Not Found"),
    @ApiError(code = 400, reason = "Bad Request"),
    @ApiError(code = 500, reason = "Internal Error")})
public PostExampleResp postExample(
    @ApiParam(value = "Description of request message",
        required = true) PostExampleReq request) 
    throws WebApplicationException{
    ...

@Api...注释是 Swagger 注释。您可以在此处查看 API 文档的现场演示:http: //swagger.io/swagger-ui/

还有一些其他项目,即:

于 2013-10-04T06:13:23.813 回答
3

我们正在研究miredot。它应该开箱即用,无需添加(m)任何额外的注释。欢迎任何反馈。

于 2014-01-24T16:13:06.323 回答