This project is a plug-in for IntelliJ IDEA, which can help java developers automatically generate swagger annotations. Supports 2021.3 and above versions
Open IntelliJ IDEA -> plugins, search for swagger-generate, install and restart
-
Select the classes, methods, and fields to be generated using the shortcut keys
alt+insert
(win) orcmd + n
(mac) to open the menu and select SwaggerGenerate -
Use the shortcut
alt+insert
(win) orcmd + n
(mac) on the class and select SwaggerGenerate
- Generate a tag based on the Controller class name
@Tag(name = {"User api"})
public class UserController {
//......
}
- Generate Schema for Dto's automatically map primitive types to be required
public class UserDto {
@Schema(description = "user name")
private String name;
@Schema(description = "user age")
private Integer age;
@Schema(required = true, description = "user age")
private int primitiveTypes;
}
- Generate generic mapping for methods
public class UserController {
@Operation(summary = "get summary", description = "Get description",
requestBody = @RequestBody(content = {@Content(schema = @Schema(implementation = DTO.class))}),
responses = @ApiResponse(responseCode = "200", description = "Ok", content = {@Content(schema = @Schema(implementation = ResponseDto.class))}))
public UserDto getUser(@Parameter(description = "user id") Long id) {
// ....
}
}