Trim trailing '/' from basePathWithoutHost (#967)

* Trim trailing '/' from basePathWithoutHost

Given that the normal use is {{{basePathWithoutHost}}}{{{path}}}.

* Trim trailing '/' from contextPath
This commit is contained in:
Benjamin Gill
2018-09-20 12:33:31 +01:00
committed by William Cheng
parent 29e9f5bda0
commit c0a6eaab85
4 changed files with 6 additions and 12 deletions

View File

@@ -193,15 +193,9 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
}
URL url = URLPathUtils.getServerURL(openAPI);
contextPath = config.escapeText(url.getPath());
basePathWithoutHost = contextPath; // for backward compatibility
basePath = config.escapeText(URLPathUtils.getHost(openAPI));
if ("/".equals(basePath.substring(basePath.length() - 1))) {
// remove trailing "/"
// https://host.example.com/ => https://host.example.com
basePath = basePath.substring(0, basePath.length() - 1);
}
contextPath = config.escapeText(url.getPath()).replaceAll("/$", ""); // for backward compatibility
basePathWithoutHost = contextPath;
basePath = config.escapeText(URLPathUtils.getHost(openAPI)).replaceAll("/$", "");
}
private void configureOpenAPIInfo() {