mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 22:20:56 +00:00
better code format in c#, aspnet generators (#11662)
This commit is contained in:
parent
c161358aa8
commit
2918b8706e
@ -49,7 +49,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
public static final String GENERATE_BODY = "generateBody";
|
||||
public static final String BUILD_TARGET = "buildTarget";
|
||||
public static final String MODEL_CLASS_MODIFIER = "modelClassModifier";
|
||||
public static final String TARGET_FRAMEWORK= "targetFramework";
|
||||
public static final String TARGET_FRAMEWORK = "targetFramework";
|
||||
|
||||
public static final String PROJECT_SDK = "projectSdk";
|
||||
public static final String SDK_WEB = "Microsoft.NET.Sdk.Web";
|
||||
@ -474,10 +474,9 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(consumesString.toString().isEmpty()) {
|
||||
if (consumesString.toString().isEmpty()) {
|
||||
consumesString = new StringBuilder("\"" + consume.get("mediaType") + "\"");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
consumesString.append(", \"").append(consume.get("mediaType")).append("\"");
|
||||
}
|
||||
|
||||
@ -502,7 +501,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
if(!consumesString.toString().isEmpty()) {
|
||||
if (!consumesString.toString().isEmpty()) {
|
||||
operation.vendorExtensions.put("x-aspnetcore-consumes", consumesString.toString());
|
||||
}
|
||||
}
|
||||
@ -621,7 +620,7 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
|
||||
compatibilityVersion = "Version_" + aspnetCoreVersion.getOptValue().replace(".", "_");
|
||||
}
|
||||
LOGGER.info("ASP.NET core version: {}", aspnetCoreVersion.getOptValue());
|
||||
if(!additionalProperties.containsKey(CodegenConstants.TEMPLATE_DIR)){
|
||||
if (!additionalProperties.containsKey(CodegenConstants.TEMPLATE_DIR)) {
|
||||
templateDir = embeddedTemplateDir = "aspnetcore" + File.separator + determineTemplateVersion(aspnetCoreVersion.getOptValue());
|
||||
}
|
||||
additionalProperties.put(COMPATIBILITY_VERSION, compatibilityVersion);
|
||||
|
@ -334,9 +334,9 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@Override
|
||||
public String apiDocFileFolder() {
|
||||
if (GENERICHOST.equals(getLibrary())){
|
||||
if (GENERICHOST.equals(getLibrary())) {
|
||||
return (outputFolder + "/" + apiDocPath + File.separatorChar + "apis").replace('/', File.separatorChar);
|
||||
}else{
|
||||
} else {
|
||||
return (outputFolder + "/" + apiDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
}
|
||||
@ -396,7 +396,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
|
||||
// avoid breaking changes
|
||||
if (GENERICHOST.equals(getLibrary())){
|
||||
if (GENERICHOST.equals(getLibrary())) {
|
||||
Comparator<CodegenProperty> comparatorByDefaultValue = new Comparator<CodegenProperty>() {
|
||||
@Override
|
||||
public int compare(CodegenProperty one, CodegenProperty another) {
|
||||
@ -502,9 +502,9 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
@Override
|
||||
public String modelDocFileFolder() {
|
||||
if (GENERICHOST.equals(getLibrary())){
|
||||
if (GENERICHOST.equals(getLibrary())) {
|
||||
return (outputFolder + "/" + modelDocPath + File.separator + "models").replace('/', File.separatorChar);
|
||||
}else{
|
||||
} else {
|
||||
return (outputFolder + "/" + modelDocPath).replace('/', File.separatorChar);
|
||||
}
|
||||
}
|
||||
@ -630,7 +630,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
clientPackage = "Client";
|
||||
|
||||
if (GENERICHOST.equals(getLibrary())){
|
||||
if (GENERICHOST.equals(getLibrary())) {
|
||||
setLibrary(GENERICHOST);
|
||||
additionalProperties.put("useGenericHost", true);
|
||||
// all c# libraries should be doing this, but we only do it here to avoid breaking changes
|
||||
@ -656,7 +656,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
additionalProperties.put("multiTarget", true);
|
||||
} else {
|
||||
// just a single value
|
||||
frameworks = new String [] {inputFramework};
|
||||
frameworks = new String[]{inputFramework};
|
||||
}
|
||||
|
||||
for (String framework : frameworks) {
|
||||
@ -749,19 +749,17 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".cs");
|
||||
}
|
||||
|
||||
if(HTTPCLIENT.equals(getLibrary())) {
|
||||
if (HTTPCLIENT.equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("FileParameter.mustache", clientPackageDir, "FileParameter.cs"));
|
||||
typeMapping.put("file", "FileParameter");
|
||||
addRestSharpSupportingFiles(clientPackageDir, packageFolder, excludeTests, testPackageFolder, testPackageName, modelPackageDir);
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
}
|
||||
else if (GENERICHOST.equals(getLibrary())){
|
||||
} else if (GENERICHOST.equals(getLibrary())) {
|
||||
addGenericHostSupportingFiles(clientPackageDir, packageFolder, excludeTests, testPackageFolder, testPackageName, modelPackageDir);
|
||||
additionalProperties.put("apiDocPath", apiDocPath + File.separatorChar + "apis");
|
||||
additionalProperties.put("modelDocPath", modelDocPath + File.separatorChar + "models");
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
addRestSharpSupportingFiles(clientPackageDir, packageFolder, excludeTests, testPackageFolder, testPackageName, modelPackageDir);
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
@ -777,7 +775,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
List<Server> servers) {
|
||||
CodegenOperation op = super.fromOperation(path, httpMethod, operation, servers);
|
||||
|
||||
if (!GENERICHOST.equals(getLibrary())){
|
||||
if (!GENERICHOST.equals(getLibrary())) {
|
||||
return op;
|
||||
}
|
||||
|
||||
@ -808,8 +806,8 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
return op;
|
||||
}
|
||||
|
||||
private void addTestInstructions(){
|
||||
if (GENERICHOST.equals(getLibrary())){
|
||||
private void addTestInstructions() {
|
||||
if (GENERICHOST.equals(getLibrary())) {
|
||||
additionalProperties.put("testInstructions",
|
||||
"/* *********************************************************************************" +
|
||||
"\n* Follow these manual steps to construct tests." +
|
||||
@ -833,7 +831,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
|
||||
public void addRestSharpSupportingFiles(final String clientPackageDir, final String packageFolder,
|
||||
final AtomicReference<Boolean> excludeTests, final String testPackageFolder, final String testPackageName, final String modelPackageDir){
|
||||
final AtomicReference<Boolean> excludeTests, final String testPackageFolder, final String testPackageName, final String modelPackageDir) {
|
||||
supportingFiles.add(new SupportingFile("IApiAccessor.mustache", clientPackageDir, "IApiAccessor.cs"));
|
||||
supportingFiles.add(new SupportingFile("Configuration.mustache", clientPackageDir, "Configuration.cs"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", clientPackageDir, "ApiClient.cs"));
|
||||
@ -842,10 +840,10 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
supportingFiles.add(new SupportingFile("ExceptionFactory.mustache", clientPackageDir, "ExceptionFactory.cs"));
|
||||
supportingFiles.add(new SupportingFile("OpenAPIDateConverter.mustache", clientPackageDir, "OpenAPIDateConverter.cs"));
|
||||
supportingFiles.add(new SupportingFile("ClientUtils.mustache", clientPackageDir, "ClientUtils.cs"));
|
||||
if(needsCustomHttpMethod) {
|
||||
if (needsCustomHttpMethod) {
|
||||
supportingFiles.add(new SupportingFile("HttpMethod.mustache", clientPackageDir, "HttpMethod.cs"));
|
||||
}
|
||||
if(needsUriBuilder) {
|
||||
if (needsUriBuilder) {
|
||||
supportingFiles.add(new SupportingFile("WebRequestPathBuilder.mustache", clientPackageDir, "WebRequestPathBuilder.cs"));
|
||||
}
|
||||
if (ProcessUtils.hasHttpSignatureMethods(openAPI)) {
|
||||
@ -883,7 +881,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
}
|
||||
|
||||
public void addGenericHostSupportingFiles(final String clientPackageDir, final String packageFolder,
|
||||
final AtomicReference<Boolean> excludeTests, final String testPackageFolder, final String testPackageName, final String modelPackageDir){
|
||||
final AtomicReference<Boolean> excludeTests, final String testPackageFolder, final String testPackageName, final String modelPackageDir) {
|
||||
supportingFiles.add(new SupportingFile("TokenProvider`1.mustache", clientPackageDir, "TokenProvider`1.cs"));
|
||||
supportingFiles.add(new SupportingFile("RateLimitProvider`1.mustache", clientPackageDir, "RateLimitProvider`1.cs"));
|
||||
supportingFiles.add(new SupportingFile("TokenContainer`1.mustache", clientPackageDir, "TokenContainer`1.cs"));
|
||||
@ -952,7 +950,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
this.optionalEmitDefaultValuesFlag = flag;
|
||||
}
|
||||
|
||||
public void setConditionalSerialization(boolean flag){
|
||||
public void setConditionalSerialization(boolean flag) {
|
||||
this.conditionalSerialization = flag;
|
||||
}
|
||||
|
||||
@ -972,10 +970,11 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
|
||||
|
||||
/**
|
||||
* Sets the api name. This value must be a valid class name.
|
||||
*
|
||||
* @param apiName The api name
|
||||
*/
|
||||
public void setApiName(String apiName) {
|
||||
if (!"".equals(apiName) && (Boolean.FALSE.equals(apiName.matches("^[a-zA-Z0-9_]*$")) || Boolean.FALSE.equals(apiName.matches("^[a-zA-Z].*")))){
|
||||
if (!"".equals(apiName) && (Boolean.FALSE.equals(apiName.matches("^[a-zA-Z0-9_]*$")) || Boolean.FALSE.equals(apiName.matches("^[a-zA-Z].*")))) {
|
||||
throw new RuntimeException("Invalid project name " + apiName + ". May only contain alphanumeric characaters or underscore and start with a letter.");
|
||||
}
|
||||
this.apiName = apiName;
|
||||
|
Loading…
x
Reference in New Issue
Block a user