What is Swagger? and how to integrate Swagger in Spring Boot? Detailed Demo – Session 22

Welcome back friends! In the previous post Session 21 we have seen how to configure MySql DB in our Spring Boot Application.
In this Post we will going to talk about how to create documentation for our Web Service endpoint.
Let say you are developing a Restful Webservice application. After completion of your work, someone should use your Webservice endpoint API right?

How do you tell how many API is available in your Webservice?
How do you tell what is the parameter for your Webservice API endpoint?
How do you tell what is the Request Boday?
How do you tell what is the response type for each Webservice API endpoint?
You can’t personally explains all your Vendor. You need to generate Documentation which should explains about your Webservice endpoint.
How to generate nice Webservice document?  Swagger come into the picture to generate nice document. Swagger is not only Webservice document generation library. it is act as a testing tool where you can test your all endpoints.

If you want to enable Swagger documentation in our Spring Boot App and following Artifact in your POM.xml file.

<dependency>
	<groupId>io.springfox</groupId>
	<artifactId>springfox-boot-starter</artifactId>
	<version>3.0.0</version>
</dependency>

We need to create Configuration file or use Application.java file where we need to add this Annotation @EnableSwagger2.
By adding this Annotation , your application capable to generate document dynamically for your API endpoint . We need to add below code in our Application.java or separate Java config file. In our case SwaggerConfiguration.java.

Please watch complete video I am explaining everything and what exactly doing below code

public static final Contact CONTACT_DETAILS = new Contact(
            "Suresh Stalin", "http://www.pinepad.com", "sales@pinepad.com");

    public static final ApiInfo API_INFO = new ApiInfo(
            "PinePad API", "PinePad API Description", "1.0",
            "urn:tos", CONTACT_DETAILS,
            "PinePad 2.0", "http://www.pinepad.com/licenses/LICENSE-2.0", Arrays.asList());

    private static final Set PRODUCES_AND_CONSUMES =
            new HashSet(Arrays.asList("application/json",
                    "application/xml"));
    @Bean
    public Docket api() {
//        return new Docket(DocumentationType.SWAGGER_2);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(API_INFO)
                .produces(PRODUCES_AND_CONSUMES)
                .consumes(PRODUCES_AND_CONSUMES);
    }

Download full source code from following GitHub link
https://github.com/sureshstalin/itgarden/tree/master/SpringBoot22
Watch following full video better understanding about Swagger Configuration.


Buy our hygiene Napkin. Our Napkins are chemical-free napkin and it has three categories.
Wings Napkin – This napkin wrapped around pure cotton cloth
https://pinepad.in/product/hygiene-eco-friendly-biodegradable-large-size-pure-cotton-cloth-wrapped-sanitary-napkin/
Wingless Napkin

https://pinepad.in/product/hygiene-eco-friendly-biodegradable-large-size-sanitary-pad-pack-4-32-pads/
Maternity Napkin for new Moms
https://pinepad.in/product/hygiene-eco-friendly-and-biodegradable-maternity-pad-pack-of-4-24-pads/ 

Close Menu
×
×

Cart