Skip to content

Commit

Permalink
added default port for server var
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario committed Oct 26, 2023
1 parent 6841e15 commit a1ba22c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class URLPathUtil {

protected static final Logger LOGGER = LoggerFactory.getLogger(URLPathUtil.class);
public static String DEFAULT_PATH = "/";
public static String DEFAULT_PORT = "8080";
public static final String LOCAL_HOST = "http://localhost:8080";

public static URL getServerURL(OpenAPI openAPI) {
Expand Down Expand Up @@ -107,7 +108,7 @@ private static String replaceServerVarsWthDefaultValues(String url, ServerVariab
.stream()
.collect(Collectors.toMap(
Map.Entry::getKey,
e -> e.getValue().getDefault()));
e -> e.getValue().getDefault() != null ? e.getValue().getDefault() : DEFAULT_PORT));
return StrSubstitutor.replace(url, defaultValues, "{", "}");
}
return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@ public void testVariableSubstitutionMissingDefault() throws Exception {
// No default for port, resulting URL is invalid.
URL url = URLPathUtil.getServerURL(openAPI, config);

Assert.assertNull(url);
Assert.assertEquals(new URL("http://myhost:8080/mypath"), url);
}
}

0 comments on commit a1ba22c

Please sign in to comment.