diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/utils/URLPathUtil.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/utils/URLPathUtil.java index ee4149bde1a..ea14e55bdbe 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/utils/URLPathUtil.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/utils/URLPathUtil.java @@ -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) { @@ -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; diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/utils/URLPathUtilTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/utils/URLPathUtilTest.java index 0f1c6fb5c51..c4bc5693ff8 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/utils/URLPathUtilTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/utils/URLPathUtilTest.java @@ -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); } }