Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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("(?<!\\$)\\{([^\\}]+)\\}");

// TODO: This should probably be moved into generator/workflow type rather than a static like this.
public static URL getServerURL(OpenAPI openAPI, Map<String, String> userDefinedVariables) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class URLPathUtilsTest {

Expand Down Expand Up @@ -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/${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") ).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]);
}
}
}
Loading