[aspnetcore] Add processing of Port defined in spec (#368)

This commit is contained in:
sunn 2018-07-03 08:23:43 +02:00 committed by Jérémie Bresson
parent 83e14a7b44
commit bece8d2a39
3 changed files with 18 additions and 3 deletions

View File

@ -21,13 +21,16 @@ import com.fasterxml.jackson.core.JsonProcessingException;
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;
@ -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();
@ -112,6 +118,13 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
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() {

View File

@ -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();
}
}

View File

@ -24,7 +24,8 @@ namespace Org.OpenAPITools
/// <returns>Webhost</returns>
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:8080/")
.Build();
}
}