Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 14, 2021 12:52 pm GMT

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:

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/**"};@Overridepublic 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!


Original Link: https://dev.to/adaendra/how-to-setup-a-gateway-for-swagger-ui-44a4

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To