DEV Community

Cover image for How to setup a gateway for Swagger UI

How to setup a gateway for Swagger UI

Maxime Guilbert
Just a dev who touches a lot of things and wants to share his experiences. (or just want to note somewhere things to don't forget)
・1 min read

If you want to setup a Swagger UI pod in your Kubernetes cluster and you have a gateway, you will have some issue if you just have exposed the main route.

If you have the issue, you will have the next message which appears in a modal with an input:

Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at then the base url is Please enter the location manually


To use it correctly, you need to allow a list of paths :

  • /swagger-ui/**
  • /swagger-resources/**
  • /swagger-ui.html
  • /v2/api-docs
  • /webjars/**
  • /view/** - [This one is configurable]


Spring Security Correction Example

private static final String[] AUTH_WHITELIST = {

public void configure(WebSecurity web) throws Exception {
Enter fullscreen mode Exit fullscreen mode


Spring Cloud Gateway predicates

        - id: swagger-ui
          uri: ${swagger-ui_url}
            - Path=/swagger-ui/**,/swagger-resources/**,/swagger-ui.html,/v2/api-docs,/webjars/**,/view/**
Enter fullscreen mode Exit fullscreen mode

I hope it will help you!

Discussion (0)