From 05b0d8f1bf3229ebda5cb338362f56a5cce6096d Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Wed, 30 Dec 2015 00:06:24 -0800 Subject: [PATCH] added `serverPort` --- .../swagger/codegen/languages/JaxRSServerCodegen.java | 10 ++++++++++ .../resources/JavaJaxRS/jersey1_18/README.mustache | 2 +- .../main/resources/JavaJaxRS/jersey1_18/pom.mustache | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java index 10b2ec77206..ae22656cd97 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JaxRSServerCodegen.java @@ -166,6 +166,16 @@ public class JaxRSServerCodegen extends JavaClientCodegen implements CodegenConf if("/".equals(swagger.getBasePath())) { swagger.setBasePath(""); } + + String host = swagger.getHost(); + String port = "8080"; + if(host != null) { + String[] parts = host.split(":"); + if(parts.length > 0) { + port = parts[1]; + } + } + this.additionalProperties.put("serverPort", port); if(swagger != null && swagger.getPaths() != null) { for(String pathname : swagger.getPaths().keySet()) { Path path = swagger.getPath(pathname); diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/README.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/README.mustache index f240464851d..7bad8dbee0a 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/README.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/README.mustache @@ -16,7 +16,7 @@ mvn clean package jetty:run You can then view the swagger listing here: ``` -http://localhost:8080{{contextPath}}/swagger.json +http://localhost:{{serverPort}}{{contextPath}}/swagger.json ``` Note that if you have configured the `host` to be something other than localhost, the calls through diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/pom.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/pom.mustache index b8426a0a693..0d1b06de43a 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/jersey1_18/pom.mustache @@ -37,7 +37,7 @@ 8079 stopit - 8080 + {{serverPort}} 60000