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 718a4c86b25..6efd0deecbe 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,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() { diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs index 3f868e0407c..78aa49e0085 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/client/mod.rs @@ -249,7 +249,7 @@ impl Api for Client where let uri = format!( - "{}//dummy", + "{}/dummy", self.base_path ); diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs index 50b0fc6207f..aceb8e42ccc 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/lib.rs @@ -35,7 +35,7 @@ mod mimetypes; pub use swagger::{ApiError, ContextWrapper}; -pub const BASE_PATH: &'static str = "/"; +pub const BASE_PATH: &'static str = ""; pub const API_VERSION: &'static str = "1.0.0"; diff --git a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs index f15596204ed..919e430b084 100644 --- a/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs +++ b/samples/server/petstore/rust-server/output/rust-server-test/src/server/mod.rs @@ -51,7 +51,7 @@ mod paths { lazy_static! { pub static ref GLOBAL_REGEX_SET: regex::RegexSet = regex::RegexSet::new(&[ - r"^//dummy$" + r"^/dummy$" ]).unwrap(); } pub static ID_DUMMY: usize = 0;