Swagger with Spring Boot REST

Swagger with Spring Boot REST | POSTMAN Tool tests our rest controllers. This is a fully manual tool, we should enter all details: URL, MethodType, Param, JSON Input, Header Details, etc.

We should list all URLs in the application, if it is a small application then it is fine. But if the application is big (having 40 controllers with multiple methods like save, update, delete, get, etc) in this case checking all URLs, types, and Input is a bit complex and time-consuming process.

Swagger is an advanced test tool compared to POSTMAN. It provides an easy UI for testing all RestControllers in the project.

If we use Swagger, we do need not to enter the URL, and choose Method Type manually. We need to enter only input data.

Swagger Configuration in Spring Boot REST

Step-1:- Define one Spring Boot project with RestControllers
Step-2:- Add the springdoc-openapi-starter-webmvc-ui dependencies

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.3.0</version>
</dependency>

See more:- Why not to use springfox-swagger2, and springfox-swagger-ui dependecies

We don’t need to add any configuration, no need to create the Docket, and no need to give the rest controller package path.

The Swagger UI page will then be available at:- http://localhost:8080/swagger-ui/index.html

Swagger UI

Swagger is not for adding any functionalities, it works only to make testing easy.

Swagger UI Sample

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *