Skip to content

Incorrect generated Server URL (always returns cached url based on first incoming request after app startup) #1031

Closed
@kardashov

Description

@kardashov

Bug description
This issue was already described in #283
The first time the /v3/api-docs endpoint is called, the server servers[0].url property is calculated and after that it is used from a cache for all subsequent calls (direct, via SwaggerUI etc.).
This issue will not manifest itself when there is only one valid path to your application (e.g. via reverse proxy url https://mydomain.com). But when there are multiple paths (like public https + plaintext http requests from internal infrastructure) this problem arises.

To Reproduce
Start the application:
send request №1:

curl --location --request GET 'http://localhost:8080/v3/api-docs' \
--header 'X-Forwarded-Proto: https' \
--header 'X-Forwarded-Host: myhost.com'

in resulting json generated servers entry is correct servers[0].url=https://myhost.com .

Send request №2:

curl --location --request GET 'http://localhost:8080/v3/api-docs' 

Expected: In generated json spec servers[0].url=http://localhost:8080 .
Actual: In generated json spec still servers[0].url=https://myhost.com

Now RESTART application and send previous requests in REVERSE ORDER (request №2, then request №1).
This time request №2 will generate correct servers[0].url=http://localhost:8080
But subsequent request №1 also shows http://localhost:8080 when https://myhost.com expected.

Expected behavior
Correct servers.url property generated in openapi.json for each incoming request (based on request's x-forwarded-* headers or their absense) not only the first one.

Additional context
SpringDoc version used 1.5.2
Changing server.forward-headers-strategy Spring property and other tricks from FAQ do not affect this behavior.
Situation even more confusing when there are multiple Api Groups defined. They will cache servers[].url property independently from each other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions