Skip to content

Spring Boot (Webflux) - Swagger UI - redirect URI does not include Gateway Prefix #42305

@dreamstar-enterprises

Description

@dreamstar-enterprises

My settings:

# spring doc settings
springdoc:
  api-docs:
    enabled: true
    version: openapi_3_1
    path: /v3/api-docs
  swagger-ui:
    enabled: true
    path: /v1/swagger-ui.html
    url: /v3/api-docs
    operations-sorter: method

# default server settings
server:
  address: ${LOCALHOST}
  port: ${RESOURCE_SERVER_PORT}
  ssl:
    enabled: false
  forward-headers-strategy: native (here framework doesn't work for me - I keep getting 403 Forbidden)
# default spring settings
spring:
  # application settings
  application:
    name: Timesheets-RESTApiApplication
  # profile settings
  profiles:
    active: dev
  # lifecycle settings
  lifecycle:
    timeout-per-shutdown-phase: ${TIMEOUT_SHUTDOWN}
  # main settings
  main:
    allow-bean-definition-overriding: true
  # webflux settings
  webflux:
    base-path: ${RESOURCE_SERVER_PREFIX}

What happens:

My Swagger link works:

http://localhost:7080/bff/api/v1/resource/swagger-ui.html

But it forwards to:

location:

/api/v1/resource/webjars/swagger-ui/index.html

which goes to

http://localhost:7080/api/v1/resource/webjars/swagger-ui/index.html

(as it misses /bff, I keep getting back 404 Not Found)

I can see my BFF forwarding the right headers in the request to the Resource Server:

Forwarded: proto=http;host="localhost:7080";for="127.0.0.1:51801"
X-Forwarded-For: 127.0.0.1
X-Forwarded-Proto: http
X-Forwarded-Prefix: /bff
X-Forwarded-Port: 7080
X-Forwarded-Host: localhost:7080
host: localhost:9090
content-length: 0
Authorization: Bearer eyJhb...

I've looked at the Spring Boot Swagger Code too

@Controller
public class SwaggerWelcomeWebFlux

    protected String buildUrlWithContextPath(String swaggerUiUrl) {
        if (this.pathPrefix == null) {
            this.pathPrefix = this.springWebProvider.findPathPrefix(this.springDocConfigProperties);
        }

        return this.buildUrl(this.contextPath + this.pathPrefix, swaggerUiUrl);
    }

This seems to ignore any Gateway prefix that might be in X-Forwarded-Prefix enabled by forward-headers-strategy: native

This looks like a bug to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions