How to setup a gateway for Swagger UI

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:


This content originally appeared on DEV Community and was authored by Maxime Guilbert

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 http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually

Solution

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]

Examples

Spring Security Correction Example

private static final String[] AUTH_WHITELIST = {
        "/swagger-resources/**",
        "/swagger-ui.html",
        "/v2/api-docs",
        "/webjars/**"
};

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers(AUTH_WHITELIST);
}

source

Spring Cloud Gateway predicates

spring:
  cloud:
    gateway:
      routes:
        - id: swagger-ui
          uri: ${swagger-ui_url}
          predicates:
            - Path=/swagger-ui/**,/swagger-resources/**,/swagger-ui.html,/v2/api-docs,/webjars/**,/view/**

I hope it will help you!


This content originally appeared on DEV Community and was authored by Maxime Guilbert


Print Share Comment Cite Upload Translate Updates
APA

Maxime Guilbert | Sciencx (2021-09-14T12:52:11+00:00) How to setup a gateway for Swagger UI. Retrieved from https://www.scien.cx/2021/09/14/how-to-setup-a-gateway-for-swagger-ui/

MLA
" » How to setup a gateway for Swagger UI." Maxime Guilbert | Sciencx - Tuesday September 14, 2021, https://www.scien.cx/2021/09/14/how-to-setup-a-gateway-for-swagger-ui/
HARVARD
Maxime Guilbert | Sciencx Tuesday September 14, 2021 » How to setup a gateway for Swagger UI., viewed ,<https://www.scien.cx/2021/09/14/how-to-setup-a-gateway-for-swagger-ui/>
VANCOUVER
Maxime Guilbert | Sciencx - » How to setup a gateway for Swagger UI. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/14/how-to-setup-a-gateway-for-swagger-ui/
CHICAGO
" » How to setup a gateway for Swagger UI." Maxime Guilbert | Sciencx - Accessed . https://www.scien.cx/2021/09/14/how-to-setup-a-gateway-for-swagger-ui/
IEEE
" » How to setup a gateway for Swagger UI." Maxime Guilbert | Sciencx [Online]. Available: https://www.scien.cx/2021/09/14/how-to-setup-a-gateway-for-swagger-ui/. [Accessed: ]
rf:citation
» How to setup a gateway for Swagger UI | Maxime Guilbert | Sciencx | https://www.scien.cx/2021/09/14/how-to-setup-a-gateway-for-swagger-ui/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.