Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}