OpenAPI 3.0 Documentation for Spring

OpenAPI v3 Swagger

The OpenAPI V3 specification is the successor to the original Swagger documentation.

This article will show you how to configure your Spring App to autogenerate the API documentation for the API you are developing.

Maven Dependency

The first step is to add the following dependency to your pom.xml

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-ui</artifactId>
    <version>1.4.2</version>
</dependency>

Setting API Definition Info

The @OpenAPIDefinition annotation allows for the specification of certain documentation details such as the name of the API services, version number, description etc.

@SpringBootApplication
@OpenAPIDefinition(info = @Info(title = "My API Service", version = "1.0", description = "The description of my service"))
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
OpenAPI v3 Swagger

Viewing The Documentation

Once you have imported the dependency, run your spring app and then visit:

localhost:8080/swagger-ui.html

Further Reading

If you liked this article, you will also find this Maven article useful as well.

You may also like...

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.