Member-only story
OpenAPI with Spring Boot: API Specification, Docker, and Jenkins Integration
Introduction
OpenAPI is a powerful specification for designing, documenting, and consuming RESTful APIs. When integrated with Spring Boot, it simplifies API development and ensures consistency. This blog will guide you through setting up OpenAPI with Spring Boot, generating an API spec file, creating a Dockerfile for the API, and setting up a Jenkins pipeline for automation.
1. Setting Up OpenAPI in Spring Boot
To integrate OpenAPI with a Spring Boot project, we will use springdoc-openapi.
Add Dependencies
<dependencies>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
</dependency>
</dependencies>
Configure OpenAPI
Create an OpenAPI configuration class:
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class OpenAPIConfig {
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.info(new Info().title("Spring Boot API")
.version("1.0")
.description("Demo API using OpenAPI"));
}
}