Spring Boot + Swagger 3 (OpenAPI 3) Hello World Example
Introduction
In previous tutorial we had implemented Spring Boot + Swagger Hello World Example. We saw what is swagger and why is it useful to implement. The example used an older version of Swagger.Also in another tutorial we have implemented Spring Boot 3 + Swagger 3 example.
What is Swagger and Open API Specification
OpenAPI Specification (formerly Swagger Specification) is an API description format for REST APIs. An OpenAPI file allows you to describe your entire API.Swagger is a set of open-source tools built around the OpenAPI Specification that can help you design, build, document and consume REST APIs.
On July 2017, the OpenAPI Specification 3.0.0 was finally released by the Open API Initiative. This has improved the specifications over the previous ones.
The springdoc-openapi java library implements the OpenAPI Specification 3.0.0 and will be used here.
Spring Boot Swagger- Table of Contents
Spring Boot 3 + Swagger Spring Boot 3 + Basic Authentication + Swagger Spring Boot + JWT + Swagger Spring Boot + Swagger Example Hello World Example Spring Boot + Swagger- Understanding the various Swagger Annotations Spring Boot + Swagger + Profile - Implementing Spring Boot Profile for a Swagger application Spring Boot + Swagger 3 (OpenAPI 3) Hello World Example Spring Boot + Swagger 3 (OpenAPI 3) + Security Example
Video
This tutorial is explained in the below Youtube Video.Lets Begin
We will be creating a spring boot project and then implementing the OpenAPI 3 specification for documenting the REST API's. The maven project we will be developing is as follows -The pom.xml will have the springdoc-openapi dependency.
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.8.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.javainuse</groupId> <artifactId>boot-swagger-3</artifactId> <version>0.0.1-SNAPSHOT</version> <name>boot-swagger-3</name> <properties> <java.version>1.8</java.version> </properties> <dependencies> <!-- Swagger UI --> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-ui</artifactId> <version>1.2.32</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>