The new .NET project file format support (#5439)

This commit is contained in:
nikitozz
2017-04-24 22:22:59 -04:00
committed by wing328
parent 9055dfc42e
commit 80dccfe395
93 changed files with 13423 additions and 8 deletions

View File

@@ -107,6 +107,8 @@ public class CodegenConstants {
public static final String PACKAGE_DESCRIPTION_DESC = "Specifies a AssemblyDescription for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
public static final String PACKAGE_COMPANY = "packageCompany";
public static final String PACKAGE_COMPANY_DESC = "Specifies an AssemblyCompany for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
public static final String PACKAGE_AUTHORS = "packageAuthors";
public static final String PACKAGE_AUTHORS_DESC = "Specifies Authors property in the .NET Core project file.";
public static final String PACKAGE_COPYRIGHT = "packageCopyright";
public static final String PACKAGE_COPYRIGHT_DESC = "Specifies an AssemblyCopyright for the .NET Framework global assembly attributes stored in the AssemblyInfo file.";
@@ -118,6 +120,9 @@ public class CodegenConstants {
public static final String OPTIONAL_ASSEMBLY_INFO = "optionalAssemblyInfo";
public static final String OPTIONAL_ASSEMBLY_INFO_DESC = "Generate AssemblyInfo.cs.";
public static final String NETCORE_PROJECT_FILE = "netCoreProjectFile";
public static final String NETCORE_PROJECT_FILE_DESC = "Use the new format (.NET Core) for .NET project files (.csproj).";
public static final String USE_COLLECTION = "useCollection";
public static final String USE_COLLECTION_DESC = "Deserialize array types to Collection<T> instead of List<T>.";

View File

@@ -18,6 +18,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
protected boolean useDateTimeOffsetFlag = false;
protected boolean useCollection = false;
protected boolean returnICollection = false;
protected boolean netCoreProjectFileFlag = false;
protected String packageVersion = "1.0.0";
protected String packageName = "IO.Swagger";
@@ -26,6 +27,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
protected String packageDescription = "A library generated from a Swagger doc";
protected String packageCompany = "Swagger";
protected String packageCopyright = "No Copyright";
protected String packageAuthors = "Swagger";
protected String interfacePrefix = "I";
@@ -161,6 +163,10 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
this.optionalMethodArgumentFlag = flag;
}
public void setNetCoreProjectFileFlag(boolean flag) {
this.netCoreProjectFileFlag = flag;
}
protected void addOption(String key, String description, String defaultValue) {
CliOption option = new CliOption(key, description);
if (defaultValue != null) option.defaultValue(defaultValue);
@@ -238,6 +244,13 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
} else {
additionalProperties.put(CodegenConstants.PACKAGE_COPYRIGHT, packageCopyright);
}
// {{packageAuthors}}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_AUTHORS)) {
setPackageAuthors((String) additionalProperties.get(CodegenConstants.PACKAGE_AUTHORS));
} else {
additionalProperties.put(CodegenConstants.PACKAGE_AUTHORS, packageAuthors);
}
// {{useDateTimeOffset}}
if (additionalProperties.containsKey(CodegenConstants.USE_DATETIME_OFFSET)) {
@@ -257,6 +270,10 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
setOptionalEmitDefaultValue(Boolean.valueOf(additionalProperties.get(CodegenConstants.OPTIONAL_EMIT_DEFAULT_VALUES).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.NETCORE_PROJECT_FILE)) {
setNetCoreProjectFileFlag(Boolean.valueOf(additionalProperties.get(CodegenConstants.NETCORE_PROJECT_FILE).toString()));
}
if (additionalProperties.containsKey(CodegenConstants.INTERFACE_PREFIX)) {
String useInterfacePrefix = additionalProperties.get(CodegenConstants.INTERFACE_PREFIX).toString();
if("false".equals(useInterfacePrefix.toLowerCase())) {
@@ -632,6 +649,10 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
public void setPackageCopyright(String packageCopyright) {
this.packageCopyright = packageCopyright;
}
public void setPackageAuthors(String packageAuthors) {
this.packageAuthors = packageAuthors;
}
public void setSourceFolder(String sourceFolder) {
this.sourceFolder = sourceFolder;

View File

@@ -151,6 +151,10 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
CodegenConstants.ALLOW_UNICODE_IDENTIFIERS_DESC,
this.allowUnicodeIdentifiers);
addSwitch(CodegenConstants.NETCORE_PROJECT_FILE,
CodegenConstants.NETCORE_PROJECT_FILE_DESC,
this.netCoreProjectFileFlag);
regexModifiers = new HashMap<Character, String>();
regexModifiers.put('i', "IgnoreCase");
regexModifiers.put('m', "Multiline");
@@ -239,6 +243,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is only supported by generated code for .NET 4+.");
} else if(NETSTANDARD.equals(targetFramework)) {
LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is not supported in .NET Standard generated code.");
} else if(Boolean.TRUE.equals(netCoreProjectFileFlag)) {
LOGGER.warn(CodegenConstants.GENERATE_PROPERTY_CHANGED + " is not supported in .NET Core csproj project format.");
} else {
setGeneratePropertyChanged(Boolean.valueOf(additionalProperties.get(CodegenConstants.GENERATE_PROPERTY_CHANGED).toString()));
}
@@ -303,7 +309,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
clientPackageDir, "ApiResponse.cs"));
supportingFiles.add(new SupportingFile("ExceptionFactory.mustache",
clientPackageDir, "ExceptionFactory.cs"));
if(Boolean.FALSE.equals(this.netStandard)) {
if(Boolean.FALSE.equals(this.netStandard) && Boolean.FALSE.equals(this.netCoreProjectFileFlag)) {
supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat"));
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh"));
@@ -311,7 +317,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
supportingFiles.add(new SupportingFile("packages.config.mustache", packageFolder + File.separator, "packages.config"));
// .travis.yml for travis-ci.org CI
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
} else {
} else if(Boolean.FALSE.equals(this.netCoreProjectFileFlag)) {
supportingFiles.add(new SupportingFile("project.json.mustache", packageFolder + File.separator, "project.json"));
}
@@ -323,7 +329,9 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
modelTestTemplateFiles.put("model_test.mustache", ".cs");
apiTestTemplateFiles.put("api_test.mustache", ".cs");
supportingFiles.add(new SupportingFile("packages_test.config.mustache", testPackageFolder + File.separator, "packages.config"));
if (Boolean.FALSE.equals(this.netCoreProjectFileFlag)) {
supportingFiles.add(new SupportingFile("packages_test.config.mustache", testPackageFolder + File.separator, "packages.config"));
}
}
if(Boolean.TRUE.equals(generatePropertyChanged)) {
@@ -337,19 +345,28 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
// UPDATE (20160612) no longer needed as the Apache v2 LICENSE is added globally
//supportingFiles.add(new SupportingFile("LICENSE", "", "LICENSE"));
if (optionalAssemblyInfoFlag) {
if (optionalAssemblyInfoFlag && Boolean.FALSE.equals(this.netCoreProjectFileFlag)) {
supportingFiles.add(new SupportingFile("AssemblyInfo.mustache", packageFolder + File.separator + "Properties", "AssemblyInfo.cs"));
}
if (optionalProjectFileFlag) {
supportingFiles.add(new SupportingFile("Solution.mustache", "", packageName + ".sln"));
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, packageName + ".csproj"));
if(Boolean.FALSE.equals(this.netStandard)) {
supportingFiles.add(new SupportingFile("nuspec.mustache", packageFolder, packageName + ".nuspec"));
if(Boolean.TRUE.equals(this.netCoreProjectFileFlag)) {
supportingFiles.add(new SupportingFile("netcore_project.mustache", packageFolder, packageName + ".csproj"));
} else {
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, packageName + ".csproj"));
if(Boolean.FALSE.equals(this.netStandard)) {
supportingFiles.add(new SupportingFile("nuspec.mustache", packageFolder, packageName + ".nuspec"));
}
}
if(Boolean.FALSE.equals(excludeTests)) {
// NOTE: This exists here rather than previous excludeTests block because the test project is considered an optional project file.
supportingFiles.add(new SupportingFile("TestProject.mustache", testPackageFolder, testPackageName + ".csproj"));
if(Boolean.TRUE.equals(this.netCoreProjectFileFlag)) {
supportingFiles.add(new SupportingFile("netcore_testproject.mustache", testPackageFolder, testPackageName + ".csproj"));
} else {
supportingFiles.add(new SupportingFile("TestProject.mustache", testPackageFolder, testPackageName + ".csproj"));
}
}
}