From c976b5a20490922974554acfdfcf5dd3df357338 Mon Sep 17 00:00:00 2001 From: Dennis Melzer Date: Wed, 17 Dec 2025 11:42:16 +0100 Subject: [PATCH 1/2] feat: no url replacement for $ variables --- .../codegen/utils/URLPathUtils.java | 2 +- .../codegen/utils/URLPathUtilsTest.java | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java index eeba04d226fb..289d9febe856 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/URLPathUtils.java @@ -38,7 +38,7 @@ public class URLPathUtils { private static final Logger LOGGER = LoggerFactory.getLogger(URLPathUtils.class); public static final String LOCAL_HOST = "http://localhost"; - public static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{([^\\}]+)\\}"); + public static final Pattern VARIABLE_PATTERN = Pattern.compile("(? userDefinedVariables) { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/URLPathUtilsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/URLPathUtilsTest.java index b2bab48e1a4b..8d6207ba0eb4 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/URLPathUtilsTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/URLPathUtilsTest.java @@ -27,6 +27,7 @@ import java.net.URL; import java.util.Arrays; import java.util.HashMap; +import java.util.Map; public class URLPathUtilsTest { @@ -204,4 +205,56 @@ public void useDefaultUrlWhenServerUrlIsNull() { URL serverURL = URLPathUtils.getServerURL(server, null); Assert.assertEquals(serverURL.toString(), "http://localhost"); } + + @Test + public void testPropertyUrl() { + String[][] testData = { + {"https://abc1.xyz:9999/some/${myProperty}", "https://abc1.xyz:9999/some/${my.property}"}, + {"HTTPS://abc2.xyz:9999/some/${my.property}", "https://abc2.xyz:9999/some/${my.property}"}, + {"http://abc3.xyz:9999/${my.property}/path", "http://abc3.xyz:9999/${my.property}/path"}, + {"HTTP://abc4.xyz:9999/some/${my.property}", "http://abc4.xyz:9999/some/${my.property}"}, + {"//abc5.xyz:9999/some/${my.property}", "http://abc5.xyz:9999/some/${my.property}"}, + {"abc6.xyz:9999/some/path", "http://abc6.xyz:9999/some/path"}, + {"localhost:9000/${my.property}", "http://localhost:9000/${my.property}"}, + {"/${my.property}/path", "http://localhost/${my.property}/path"}, + {"https://abc1.xyz:9999/some/${my.property}/{version}", "https://abc1.xyz:9999/some/${my.property}/v1"}, + {"HTTPS://abc2.xyz:9999/${my.property}/{version}", "https://abc2.xyz:9999/${my.property}/v1"}, + {"https://abc1.xyz:9999/some/${version}/${my.property}", "https://abc1.xyz:9999/some/v1/${my.property}"}, + {"HTTPS://abc2.xyz:9999/{version}/${my.property}/", "https://abc2.xyz:9999/v1/${my.property}"} + + }; + + for (String[] t : testData) { + OpenAPI openAPI = new OpenAPI(); + openAPI.addServersItem(new Server().url(t[0])); + + Assert.assertEquals(URLPathUtils.getServerURL(openAPI, Map.of("version", "v1") ).toString(), t[1]); + } + } + + @Test + public void testPropertyUrlInVariable() { + String[][] testData = { + {"https://abc1.xyz:9999/some/{my.property}", "https://abc1.xyz:9999/some/${my.property}"}, + {"HTTPS://abc2.xyz:9999/some/{my.property}", "https://abc2.xyz:9999/some/${my.property}"}, + {"http://abc3.xyz:9999/{my.property}/path", "http://abc3.xyz:9999/${my.property}/path"}, + {"HTTP://abc4.xyz:9999/some/{my.property}", "http://abc4.xyz:9999/some/${my.property}"}, + {"//abc5.xyz:9999/some/{my.property}", "http://abc5.xyz:9999/some/${my.property}"}, + {"abc6.xyz:9999/some/path", "http://abc6.xyz:9999/some/path"}, + {"localhost:9000/{my.property}", "http://localhost:9000/${my.property}"}, + {"/{my.property}/path", "http://localhost/${my.property}/path"}, + {"https://abc1.xyz:9999/some/{my.property}/{version}", "https://abc1.xyz:9999/some/${my.property}/v1"}, + {"HTTPS://abc2.xyz:9999/{my.property}/{version}", "https://abc2.xyz:9999/${my.property}/v1"}, + {"https://abc1.xyz:9999/some/${version}/{my.property}", "https://abc1.xyz:9999/some/v1/${my.property}"}, + {"HTTPS://abc2.xyz:9999/{version}/{my.property}/", "https://abc2.xyz:9999/v1/${my.property}"} + + }; + + for (String[] t : testData) { + OpenAPI openAPI = new OpenAPI(); + openAPI.addServersItem(new Server().url(t[0])); + + Assert.assertEquals(URLPathUtils.getServerURL(openAPI, Map.of("version", "v1", "my.property", "${my.property}") ).toString(), t[1]); + } + } } From 46e32954e6130a8a97c59bbec18289ba5abb1e30 Mon Sep 17 00:00:00 2001 From: Dennis Melzer Date: Wed, 17 Dec 2025 11:44:09 +0100 Subject: [PATCH 2/2] fix test --- .../openapitools/codegen/utils/URLPathUtilsTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/URLPathUtilsTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/URLPathUtilsTest.java index 8d6207ba0eb4..d74d8b5a3e39 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/URLPathUtilsTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/URLPathUtilsTest.java @@ -209,7 +209,7 @@ public void useDefaultUrlWhenServerUrlIsNull() { @Test public void testPropertyUrl() { String[][] testData = { - {"https://abc1.xyz:9999/some/${myProperty}", "https://abc1.xyz:9999/some/${my.property}"}, + {"https://abc1.xyz:9999/some/${my.property}", "https://abc1.xyz:9999/some/${my.property}"}, {"HTTPS://abc2.xyz:9999/some/${my.property}", "https://abc2.xyz:9999/some/${my.property}"}, {"http://abc3.xyz:9999/${my.property}/path", "http://abc3.xyz:9999/${my.property}/path"}, {"HTTP://abc4.xyz:9999/some/${my.property}", "http://abc4.xyz:9999/some/${my.property}"}, @@ -219,8 +219,8 @@ public void testPropertyUrl() { {"/${my.property}/path", "http://localhost/${my.property}/path"}, {"https://abc1.xyz:9999/some/${my.property}/{version}", "https://abc1.xyz:9999/some/${my.property}/v1"}, {"HTTPS://abc2.xyz:9999/${my.property}/{version}", "https://abc2.xyz:9999/${my.property}/v1"}, - {"https://abc1.xyz:9999/some/${version}/${my.property}", "https://abc1.xyz:9999/some/v1/${my.property}"}, - {"HTTPS://abc2.xyz:9999/{version}/${my.property}/", "https://abc2.xyz:9999/v1/${my.property}"} + {"https://abc1.xyz:9999/some/{version}/${my.property}", "https://abc1.xyz:9999/some/v1/${my.property}"}, + {"HTTPS://abc2.xyz:9999/{version}/${my.property}", "https://abc2.xyz:9999/v1/${my.property}"} }; @@ -245,8 +245,8 @@ public void testPropertyUrlInVariable() { {"/{my.property}/path", "http://localhost/${my.property}/path"}, {"https://abc1.xyz:9999/some/{my.property}/{version}", "https://abc1.xyz:9999/some/${my.property}/v1"}, {"HTTPS://abc2.xyz:9999/{my.property}/{version}", "https://abc2.xyz:9999/${my.property}/v1"}, - {"https://abc1.xyz:9999/some/${version}/{my.property}", "https://abc1.xyz:9999/some/v1/${my.property}"}, - {"HTTPS://abc2.xyz:9999/{version}/{my.property}/", "https://abc2.xyz:9999/v1/${my.property}"} + {"https://abc1.xyz:9999/some/{version}/{my.property}", "https://abc1.xyz:9999/some/v1/${my.property}"}, + {"HTTPS://abc2.xyz:9999/{version}/{my.property}", "https://abc2.xyz:9999/v1/${my.property}"} };