Tim TwiestTurns out I create, break, and fix things.

I'm a full-stack developer, currently working at PanCompany ↗

Spring Boot and OpenAPI

Integrate OpenAPI into a Spring Boot Rest API


Our first step is to create the root module. This cornerstone module functions as the parent, housing the dependencies shared across all other modules. By centralizing these dependencies, we streamline our development process and ensure consistency across the project.

In this Spring Boot application, the common dependencies you'll find in our root module include:

  • Spring Boot: The core framework for building standalone, production-grade Spring based applications.
  • Spring Web: A module for creating web applications.
  • Spring Test: A framework for testing Spring applications.
  • Lombok: A Java library that helps to reduce boilerplate code.

Let's take a look at the Maven pom.xml configuration for our root module:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">


    <!--  Maven Project/Build Settings  -->

    <!--  Maven Version Management  -->

    <!--  General Dependencies  -->

    <!--  Spring Dependencies  -->



With the root module established, our next move is to create two additional directories within our project. These will serve as distinct modules named ws and api.

Here is what you should do:

  • Create two directories named spring-boot-rest-api-with-openapi-api and spring-boot-rest-api-with-openapi-ws in your project root.
  • The api module is where we'll define our OpenAPI specification
  • The ws module, on the other hand, will be responsible for implementing these interfaces and managing our web services.

Once these directories are created, we need to declare these new modules in our root pom.xml file. This informs Maven about the hierarchical structure of our project and the interdependencies of our modules.

Let's declare our modules as follows:


With this configuration in place, we can now begin to define our OpenAPI specification.

Create the API module

openapi: 3.0.3
  version: 1.0.0
  title: My API
  - url: /api
# ...

Create the Web module