Skip to content

Commit

Permalink
Merge pull request #407 from swagger-api/option_for_generator_service
Browse files Browse the repository at this point in the history
[aspnetcore] process interface and asp version as cliOption, codegenArguments and additionalProperties
  • Loading branch information
frantuma authored Jun 28, 2019
2 parents 0e34384 + dc7b3e5 commit 9cf694a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3590,9 +3590,7 @@ public List<CodegenArgument> readLanguageArguments() {
String shortOption = argument.findValue("shortOption") != null ? argument.findValue("shortOption").textValue() : null;
String type = argument.findValue("type") != null ? argument.findValue("type").textValue() : "string";
boolean isArray = argument.findValue("isArray") != null ? argument.findValue("isArray").booleanValue() : false;
if (StringUtils.isBlank(option)) {
continue;
}

languageArguments.add(new CodegenArgument()
.option(option)
.shortOption(shortOption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,19 @@ public AspNetCoreServerCodegen() {
this.returnICollection);

this.aspNetCoreVersion = DEFAULT_ASP_NET_CORE_VERSION;

addSwitch(INTERFACE_ONLY_OPTION.substring(2),
"Only generate interfaces for controllers",
false);

addSwitch(INTERFACE_CONTROLLER_OPTION.substring(2),
"Generate interfaces for controllers, implemented by a default controller implementation",
false);

addOption(ASP_NET_CORE_VERSION_OPTION.substring(2),
"ASP.NET Core version",
DEFAULT_ASP_NET_CORE_VERSION);

}

@Override
Expand Down Expand Up @@ -299,8 +312,25 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecurityScheme> securitySc
}

private void addInterfaceControllerTemplate() {
boolean interfaceOnly = Boolean.valueOf(getOptionValue(INTERFACE_ONLY_OPTION));
boolean interfaceController = Boolean.valueOf(getOptionValue(INTERFACE_CONTROLLER_OPTION));
String interfaceOnlyOption = getOptionValue(INTERFACE_ONLY_OPTION);
boolean interfaceOnly = false;
if (StringUtils.isNotBlank(interfaceOnlyOption)) {
interfaceOnly = Boolean.valueOf(getOptionValue(INTERFACE_ONLY_OPTION));
} else {
if (additionalProperties.get(INTERFACE_ONLY_OPTION.substring(2)) != null) {
interfaceOnly = Boolean.valueOf(additionalProperties.get(INTERFACE_ONLY_OPTION.substring(2)).toString());
}
}

String interfaceControllerOption = getOptionValue(INTERFACE_CONTROLLER_OPTION);
boolean interfaceController = false;
if (StringUtils.isNotBlank(interfaceControllerOption)) {
interfaceController = Boolean.valueOf(getOptionValue(INTERFACE_CONTROLLER_OPTION));
} else {
if (additionalProperties.get(INTERFACE_CONTROLLER_OPTION.substring(2)) != null) {
interfaceController = Boolean.valueOf(additionalProperties.get(INTERFACE_CONTROLLER_OPTION.substring(2)).toString());
}
}

if (interfaceController) {
apiTemplateFiles.put("icontroller.mustache", ".cs");
Expand All @@ -321,9 +351,14 @@ public String getArgumentsLocation() {
private void setAspNetCoreVersion() {
String optionValue = getOptionValue(ASP_NET_CORE_VERSION_OPTION);
if (StringUtils.isBlank(optionValue)) {
return;
if (additionalProperties.get(ASP_NET_CORE_VERSION_OPTION.substring(2)) != null) {
this.aspNetCoreVersion = additionalProperties.get(ASP_NET_CORE_VERSION_OPTION.substring(2)).toString();
} else {
return;
}
} else {
this.aspNetCoreVersion = optionValue;
}
this.aspNetCoreVersion = optionValue;
if (!this.aspNetCoreVersion.equals("2.0") && !this.aspNetCoreVersion.equals("2.1") && !this.aspNetCoreVersion.equals("2.2")) {
LOGGER.error("version '" + this.aspNetCoreVersion + "' is not supported, switching to default version: '" + DEFAULT_ASP_NET_CORE_VERSION + "'");
this.aspNetCoreVersion = DEFAULT_ASP_NET_CORE_VERSION;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/arguments/inflector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ arguments:
type: "boolean"
- option: "--use-oas2"
description: "use OpenAPI v2.0 (Swagger 1.5.x) annotations (by default, OpenAPI v3.0 is used)."
type: "boolean"
type: "boolean"
2 changes: 1 addition & 1 deletion src/main/resources/arguments/java.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ arguments:
type: "string"
- option: "--use-oas2"
description: "use OpenAPI v2.0 (Swagger 1.5.x) annotations (by default, OpenAPI v3.0 is used)."
type: "boolean"
type: "boolean"

0 comments on commit 9cf694a

Please sign in to comment.