I am trying to add OpenApi to my Spring Boot Gradle project. I've added the OpenAPI plugin to my build.gradle
file, but when I start my app, none of the URLs that are supposed to make documentation seem to get generated.
build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.1-SNAPSHOT'
id 'io.spring.dependency-management' version '1.1.0'
id "org.springdoc.openapi-gradle-plugin" version "1.6.0"
}
group = 'com.sampleproject'
sourceCompatibility = '17'
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
application.properties
server.servlet.context-path=/sample-service
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/swagger-ui-custom.html
I have tried building and running my project with:
./gradlew clean build
followed by java -jar build/libs/name-of-jar-file.jar
./gradlew clean generateOpenApiDocs
Links that I've been using:
Both links say to add the plugin, which I did. When my app is running, I try going to http://localhost:8080/sample-service/api-docs
and http://localhost:8080/sample-service/swagger-ui-custom.html
, and both give me the standard spring white label error page.
I have two controller classes in my application, and all endpoints work fine when my app is running.
What am I missing or doing wrong in order to get OpenAPI to work with my Spring Boot Gradle application?
In order to enable swagger UI, you will need to add the plugin of
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.14'
Adding this to build.gradle dependencies will solve your problem. I hope this helps.