Skip to content

Invalid server url when springdoc.api-docs.path defined #3082

@tuomari

Description

@tuomari

When springdoc.api-docs.path is defined to for example /documents/v3/api-docs server url becomes invalid:

"servers": [
        {
            "url": "http://loca",
            "description": "Generated server url"
        }
    ],

the url should be http://localhost:8080

The culprit seems to be this snippet of code, where prefix becomes /documents, but apiDocsUrl already contains the prefix: /documents/v3/api-docs, so the prefix length gets subtracted twice.

protected String getServerUrl(HttpServletRequest request, String apiDocsUrl) {
String requestUrl = decode(request.getRequestURL().toString());
Optional<SpringWebProvider> springWebProviderOptional = springDocProviders.getSpringWebProvider();
String prefix = StringUtils.EMPTY;
if (springWebProviderOptional.isPresent())
prefix = springWebProviderOptional.get().findPathPrefix(springDocConfigProperties);
return requestUrl.substring(0, requestUrl.length() - apiDocsUrl.length() - prefix.length());
}

Image

Version info

Spring boot version 3.5.5
springdoc-openapi-starter-webmvc-ui : 2.8.12

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions