From 01dbb8b693479ca27c94f443c4b4683b1675fed4 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 30 Jul 2018 15:09:56 +0800 Subject: [PATCH] fix base path when it's not defined in the spec (#678) --- .../java/org/openapitools/codegen/DefaultGenerator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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() {