Swagger And Spring Boot (Rest Documentation)

Please Learning Swagger documentation for rest.

To Add Swagger to your application

add the depedencies :


And then create create swagger class configuration, example : SwaggerConfiguration class

public class SwaggerConfig {
    public Docket productAPI(){
       return new Docket(DocumentationType.SWAGGER_2)
    private ApiInfo metaInfo(){
        return new ApiInfo(
                "Spring boot Swagger",
                "Learning Swagger",
                "Tearm Of Service",
                new Contact("diarycoding",
                "Apache License Version 2.0",
                new ArrayList<>()

Add annotation on @ApiOperation

@ApiOperation(value = "Get All Data",
        responseContainer = "List",
        produces = "application/json",
        response = Product.class)
public Iterable<Product> getProduct(){
    return products;

@ApiModel and @ApiModelProperty
this is used for tell consumer application
about information the property (response/ request)
example :

@ApiModel(value = "Product Model For display and Saving Data")
public class Product {
    private String id;
    @ApiModelProperty(notes = "Code Product",
            required = true,
            allowEmptyValue = false,
            dataType = "String"
    private String code;
    private String name;
    private Long stock;

How to Run Application :

In Server :

mvn spring-boot:run

Open in Browser :



Leave a Comment.