Maven How To Generate Swagger Documents

Do you like this?

This article shows you how to generate Swagger static documents such as HTML from Maven.


The end result of this is to be able to run a command like:

mvn exec:exec -Pdoc
To do this you need to have swagger dependencies in your pom.xml




							<classpath />
Please make sure you change the URL to your swagger json document. You will also need to put Swagger style documentation in your java code. Below is an example.
@RequestMapping(value = "/users")
@Api(value = "User", description = "User API")
public class UserController {

    @RequestMapping(method = RequestMethod.POST)
    @ApiOperation(value = "create a new user", produces = "application/json",
                        response = User.class)
    @ApiResponses(value = {
            @ApiResponse(code = 201, message = "success", response = User.class)
    public ResponseEntity createFittingStation(
			@ApiParam(value = "user", required = true) final UserDTO user) {
        return new ResponseEntity(userService.createUser(user), HttpStatus.CREATED);


public class User {

    private Long id;

    @ApiModelProperty(required = true)
    private String firstName;

    @ApiModelProperty(required = true)
    private String lastName;

comments powered by Disqus