Generating Swagger documentation from existing Java code?
The process for generating swagger definition from existing code is simple.
Add the following dependencies (I happen to use Maven):
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
This adds a swagger-ui
in your application that can be accessed with
http://<host>:<port>/swagger-ui.html
Hit the API documentation (/v2/api-docs) link and you will get a JSON file that can be easily converted to YAML file using http://editor.swagger.io (Edit -> Convert to YAML)