Swagger UI configuration for API-Gateway in Spring Boot
In this article, we will discuss managing different Swagger-UIs of various microservices using just one Swagger-UI.

OVERVIEW
In our microservices setup, each microservice comes with its own set of unique APIs. When it comes to interacting with these APIs, we’re faced with two options: either navigate through the specific endpoints and individual URLs of each microservice or streamline the process by sending requests to all of them from a central location. This centralized point, often known as an API Gateway, is instrumental in consolidating requests.
Typically, an API Gateway serves as a unified entry point for managing and directing requests. In our case, we plan to leverage the API Gateway to not only simplify the process but also to gain access to the APIs, specifically their Swagger-UIs. By configuring a Swagger-UI within the Gateway, we can conveniently interact with the various Swagger-UIs offered by different microservices.
Firstly
First, let’s take a look at the configs we’ll add in microservices.

- Include this dependency in the build.gradle file.
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.4'!! When copying this, check if the following config is present below; otherwise, it won’t work.
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
}
ext {
set('springCloudVersion', "2023.0.0-RC1")
}
#dependency...
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}2. Paste the config into the application.yaml file.
server:
port: 8081
servlet:
context-path: /
spring:
application:
name: TEST-SERVICE
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
openapi:
service:
title: test-service doc
version: 1.0.0
url: http://localhost:8080 #api gateway url
springdoc:
api-docs:
path: /test-service/v3/api-docs
swagger-ui:
path: /test-service/swagger-ui.htmlHere, the config for (eureka) is meant for establishing a connection between API Gateway and microservices.
I’ll inform you about the eureka installation at the end of the article.
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eurekaSecond
Now, let’s configure the settings for API Gateway.

- Include this dependency in the build.gradle file.
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' // This config is only for establishing a connection with microservices.
implementation 'org.springframework.cloud:spring-cloud-starter-gateway'
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:2.0.2'2. Paste the config into the application.yaml file.
server:
servlet:
context-path:
port: 8080
spring:
application:
name: GATEWAY-SERVICE
cloud:
gateway:
routes:
- id: test-service-route
uri: http://localhost:8081
predicates:
- Path=/test-service/v3/api-docs
- Method=GET
main:
web-application-type: reactive
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka
springdoc:
api-docs:
enabled: true
swagger-ui:
enabled: true
path: /swagger-ui.html
config-url: /v3/api-docs/swagger-config
urls:
- url: /v3/api-docs
name: API Gateway Service
- url: /test-service/v3/api-docs
name: Test ServiceUse this for API Gateway Swagger UI. http://localhost:8080/swagger-ui.html

Finally
The configurations used for the Eureka server are meant to establish a connection between microservices and API Gateway.
You can read my article to set up Eureka Server.



