Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Merge branch 'master' into ihsmarkitoss-feature/cleanup
* master: (48 commits)
  [Typescript AngularJS] fix Extra package prefix in api parameters operations (#2522)
  #1023 - [Scala] Use status family during response processing (#1024)
  Generate setters for readonly properties in server code (#1582)
  [JS] fix NPE for null string and improve Travis config file (#2553)
  [elm] Update ISO 8601 library (fixes missing time zone designator) (#2545)
  [csharp] update sample after #2528 (#2550)
  [JavaScript] fix index.js, ApiClient.js and test files generated to incorrect location (#2511)
  Aspnetcore nullable support (#2529)
  Csharp nullable support (#2528)
  [C++] [Qt5] Add enum support for client and server (#2339)
  Fixed typo in migration-from-swagger-codegen.md (#2548)
  [TypeScript Client] fix install Aurelia + fix use deprecated function (#2514)
  [KOTLIN] fix var name not correctly sanitized (#2537)
  Update swagger-parser to '2.0.11-OpenAPITools.org-1' (#2262)
  Add @karismann to Java and Kotlin technical committee (#2542)
  Add GoDaddy to the list of companies using OpenAPI Generator (#2541)
  [Kotlin SpringBoot Server] alternative: fix optional parameter not correctly declared in service (#2539)
  improve indentation, update dependencies (#2521)
  update kotlin spring samples
  [JAVA] Use specified data type in enum's fromValue instead of string (#2347)
  ...
  • Loading branch information
jimschubert committed Apr 1, 2019
commit 9844afa5ad4eacb8b5354d79a8eae0ccccd425d0
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.samskivert.mustache.Mustache;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.URLPathUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -54,8 +55,8 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
private boolean useSwashbuckle = true;
protected int serverPort = 8080;
protected String serverHost = "0.0.0.0";
protected CliOption aspnetCoreVersion= new CliOption(ASPNET_CORE_VERSION,"ASP.NET Core version: 2.2 (default), 2.1, 2.0 (deprecated)");; // default to 2.1
private CliOption classModifier = new CliOption(CLASS_MODIFIER,"Class Modifier can be empty, abstract");
private CliOption aspnetCoreVersion = new CliOption(ASPNET_CORE_VERSION, "ASP.NET Core version: 2.2 (default), 2.1, 2.0 (deprecated)");
private CliOption classModifier = new CliOption(CLASS_MODIFIER, "Class Modifier can be empty, abstract");
private CliOption operationModifier = new CliOption(OPERATION_MODIFIER, "Operation Modifier can be virtual, abstract or partial");
private boolean generateBody = true;
private CliOption buildTarget = new CliOption("buildTarget", "Target to build an application or library");
Expand Down Expand Up @@ -136,7 +137,7 @@ public AspNetCoreServerCodegen() {
aspnetCoreVersion.addEnum("2.2", "ASP.NET COre V2.2");
aspnetCoreVersion.setDefault("2.2");
aspnetCoreVersion.setOptValue(aspnetCoreVersion.getDefault());
addOption(aspnetCoreVersion.getOpt(),aspnetCoreVersion.getDescription(),aspnetCoreVersion.getOptValue());
addOption(aspnetCoreVersion.getOpt(), aspnetCoreVersion.getDescription(), aspnetCoreVersion.getOptValue());

// CLI Switches
addSwitch(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG,
Expand All @@ -163,19 +164,19 @@ public AspNetCoreServerCodegen() {
classModifier.addEnum("abstract", "Make class abstract");
classModifier.setDefault("");
classModifier.setOptValue(classModifier.getDefault());
addOption(classModifier.getOpt(),classModifier.getDescription(),classModifier.getOptValue());
addOption(classModifier.getOpt(), classModifier.getDescription(), classModifier.getOptValue());

operationModifier.addEnum("virtual", "Keep method virtual ");
operationModifier.addEnum("abstract", "Make method abstract");
operationModifier.setDefault("virtual");
operationModifier.setOptValue(operationModifier.getDefault());
addOption(operationModifier.getOpt(),operationModifier.getDescription(),operationModifier.getOptValue());
addOption(operationModifier.getOpt(), operationModifier.getDescription(), operationModifier.getOptValue());

buildTarget.addEnum("program", "Generate code for standalone server");
buildTarget.addEnum("library", "Generate code for a server abstract class lbrary");
buildTarget.setDefault("program");
buildTarget.setOptValue(buildTarget.getDefault());
addOption(buildTarget.getOpt(),buildTarget.getDescription(),buildTarget.getOptValue());
addOption(buildTarget.getOpt(), buildTarget.getDescription(), buildTarget.getOptValue());

addSwitch(GENERATE_BODY,
"Generates method body.",
Expand Down Expand Up @@ -326,7 +327,20 @@ public String toRegularExpression(String pattern) {
return escapeText(pattern);
}

private void setCliOption(CliOption cliOption) throws IllegalArgumentException {
@Override
public String getNullableType(Schema p, String type) {
boolean isNullableExpected = p.getNullable() == null || (p.getNullable() != null && p.getNullable());

if (isNullableExpected && languageSpecificPrimitives.contains(type + "?")) {
return type + "?";
} else if (languageSpecificPrimitives.contains(type)) {
return type;
} else {
return null;
}
}

private void setCliOption(CliOption cliOption) throws IllegalArgumentException {
if (additionalProperties.containsKey(cliOption.getOpt())) {
cliOption.setOptValue(additionalProperties.get(cliOption.getOpt()).toString());
if (cliOption.getOptValue() == null) {
Expand All @@ -347,7 +361,7 @@ private void setClassModifier() {
if ("abstract".equals(classModifier.getOptValue())) {
operationModifier.setOptValue(classModifier.getOptValue());
additionalProperties.put(OPERATION_MODIFIER, operationModifier.getOptValue());
LOGGER.warn("classModifier is " + classModifier.getOptValue() + " so forcing operatonModifier to "+ operationModifier.getOptValue());
LOGGER.warn("classModifier is " + classModifier.getOptValue() + " so forcing operatonModifier to " + operationModifier.getOptValue());
} else {
setCliOption(operationModifier);
}
Expand All @@ -360,8 +374,8 @@ private void setOperationModifier() {
if ("abstract".equals(operationModifier.getOptValue())) {
generateBody = false;
additionalProperties.put(GENERATE_BODY, generateBody);
LOGGER.warn("operationModifier is " + operationModifier.getOptValue() + " so forcing generateBody to "+ generateBody);
} else if (additionalProperties.containsKey(GENERATE_BODY)) {
LOGGER.warn("operationModifier is " + operationModifier.getOptValue() + " so forcing generateBody to " + generateBody);
} else if (additionalProperties.containsKey(GENERATE_BODY)) {
generateBody = convertPropertyToBooleanAndWriteBack(GENERATE_BODY);
} else {
additionalProperties.put(GENERATE_BODY, generateBody);
Expand Down Expand Up @@ -389,7 +403,7 @@ private void setAspnetCoreVersion(String packageFolder) {
} else {
// default, do nothing
LOGGER.info("ASP.NET core version: " + aspnetCoreVersion.getOptValue());
compatibilityVersion = "Version_" + aspnetCoreVersion.getOptValue().replace(".","_");
compatibilityVersion = "Version_" + aspnetCoreVersion.getOptValue().replace(".", "_");
}
additionalProperties.put(COMPATIBILITY_VERSION, compatibilityVersion);
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.