mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 10:58:55 +00:00
[aspnetcore] Add processing of Port defined in spec (#368)
This commit is contained in:
parent
83e14a7b44
commit
bece8d2a39
@ -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() {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user