diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index 503bf241359..7bd9ff212bd 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -193,8 +193,14 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { URL url = URLPathUtils.getServerURL(openAPI); contextPath = config.escapeText(url.getPath()); - basePath = config.escapeText(URLPathUtils.getHost(openAPI)); 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); + } + } private void configureOpenAPIInfo() {