-
-
Notifications
You must be signed in to change notification settings - Fork 543
Closed
Labels
wontfixThis will not be worked onThis will not be worked on
Description
Describe the bug
When there are two possible URLs, such as /v3/api-docs and /${spring.application.name}/v3/api-docs,it might lead to an exception during the requestUrl.substring operation if the requestUrl used during access doesn't include ${spring.application.name}.
In such cases, the length of the prefix would exceed the length of the requestUrl, causing an issue.
To Reproduce
Steps to reproduce the behavior:
I added the following code for forwarding in the service layer:
@Controller
public class AggregatedDocGatewayForward {
@GetMapping("/${spring.application.name}/v3/api-docs/{param}")
public String forwardV3ApiDocsParam(@PathVariable String param) {
return "forward:/v3/api-docs/" + param;
}
@GetMapping(value = {"/${spring.application.name}/v3/api-docs"
, "/${spring.application.name}/v3/api-docs/default"})
public String forwardV3ApiDocs() {
return "forward:/v3/api-docs";
}
}
The following code may occasionally result in an exception:
org.springdoc.webmvc.api.OpenApiWebMvcResource:
@Override
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());
}
Metadata
Metadata
Assignees
Labels
wontfixThis will not be worked onThis will not be worked on