Using Javadocs to generate Swagger document(使用 Javadocs 生成 Swagger 文档)
问题描述
我想为现有的一组 RESTful API 构建 Swagger 文档.我有以下要求:
I want to build the Swagger documentation for an existing set of RESTful APIs. I have the following requirement:
- 离线生成 Swagger Doc(我用 http://kongchen.github.io/swagger-maven-plugin/).这个插件帮助我在编译期间生成 Swagger 文档.
- 阅读现有的 Javadoc,以便在 Swagger 文档中使用它们.
- Generate Swagger Doc offline (I used http://kongchen.github.io/swagger-maven-plugin/). This plugin helps me to generate the Swagger documentation during compile time.
- Reading the existing Javadoc so that they can be used in the Swagger documentation.
到目前为止,使用上述插件我能够实现第 1 点.所以对于现有的 REST 方法:
So far using the above plugin I was able to achieve point no 1. So for an existing REST method:
我能够生成 Swagger 文档.@ApiOperation & 的使用@ApiResponses 让我的文档看起来很棒.
I was able to generate the Swagger documentation. The usage of @ApiOperation & @ApiResponses makes my documentation looks great.
但是,我的问题是我是否可以使用 Javadocs 而不是让每个开发人员都创建 @ApiOperation &@ApiResponses 以便为我的团队节省时间?
However, my question is can I use the Javadocs instead of making every developer to create @ApiOperation & @ApiResponses so that it saves time for my team?
推荐答案
您可以使用 Enunciate 从 Javadoc 生成 swagger-ui,它有一个 Swagger 模块.首先,您需要将 maven 插件添加到您的 pom 文件中;例如
You can generate swagger-ui from Javadoc by using Enunciate, which has a Swagger module. First, you need to add the maven plugin to your pom file; e.g.
其中 'enunciate.xml' 包含您的项目特定配置,如下所示:
where 'enunciate.xml' contains your project specific configurations and looks like this:
然后运行 mvn compile
它将从您的 Javadoc 生成 Swagger 文档文件.
Then run mvn compile
and it will generate Swagger documentation files from your Javadoc.
这篇关于使用 Javadocs 生成 Swagger 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!