Skip to content

Commit

Permalink
[aspnetcore] Add processing of Port defined in spec (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
etherealjoy authored and jmini committed Jul 3, 2018
1 parent 83e14a7 commit bece8d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@

import com.samskivert.mustache.Mustache;

import io.swagger.v3.oas.models.OpenAPI;

import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.ModelUtils;

import org.openapitools.codegen.utils.URLPathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URL;
import java.util.*;

import static java.util.UUID.randomUUID;
Expand All @@ -42,6 +45,9 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
protected Logger LOGGER = LoggerFactory.getLogger(AspNetCoreServerCodegen.class);

private boolean useSwashbuckle = true;
protected int serverPort = 8080;
protected String serverHost = "0.0.0.0";


public AspNetCoreServerCodegen() {
super();
Expand Down Expand Up @@ -112,6 +118,13 @@ public String getName() {
public String getHelp() {
return "Generates an ASP.NET Core Web API server.";
}
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
super.preprocessOpenAPI(openAPI);
URL url = URLPathUtils.getServerURL(openAPI);
additionalProperties.put("serverHost", url.getHost());
additionalProperties.put("serverPort", URLPathUtils.getPort(url, 8080));
}

@Override
public void processOpts() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace {{packageName}}
/// <returns>Webhost</returns>
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:{{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}8080{{/serverPort}}/")
.Build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static void Main(string[] args)
/// <returns>Webhost</returns>
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:8080/")
.Build();
}
}

0 comments on commit bece8d2

Please sign in to comment.