[C#] Adding support for generating .NET Standard 1.3 client library (#4955)

* [CsharpNetStandard] Added C# .NET Standard Client Generation

Added language CsharpNetStandard.
Everything copied from csharp Client Generator.
Dependancies switched from Restsharp to Restsharp.Portable.
Changes made where nececary to replicate Restsharp functionallity.
Project type changed to .NET Standard protable library.

* [CsharpNetStandard] Removed client prop validation due to incompability

* [CsharpNetStandard] Minor fixes

Changed leftover RestSharp.Method to Method
Changed to .Net Standard 1.3 for compability reasons
Changed excludeTests to default to true due to tests not being implemented yet

Removed unnecessary targetFramework property
Removed leftover UWP stuff

* [CsharpNetStandard] More fixes

Added correct dependencies to Readme
Added correct supported frameworks to Readme
Added slightly better placeholder for installation instructions in Readme

Removed leftover dependencies from project.json
Removed leftover SupportsAsync stuff
Removed references to build.bat/-.sh since they're not yet being generated

Todo implement test generation

* [CsharpNetStandard] Added forgoten git_push.sh

* [C#-netstandard] Renamed option to csharp-netstandard

Also added .bat file for test generation

* [C# Net Standard] fixed path in .bat file

* [C# NET Standard] fixes to enum generation

Fixed issues with enum generation due to tired programmer

* [C# NET Standard] Generated sample client library

Sample library generated

Fixes:
Class actually works again
.bat - minor inconsistency fixed

* [C# NET Standard] Error corrected in how timeout is set

Configuration Timeout property changed to TimeSpan type and code corrected around that

* [C#] Merged .NET Standard generator into csharp generator

Functionallity of csharp-netstarndard generator has been moved into standard csharp generator under the targetFramework option as "v5.0"
This commit is contained in:
Gronsak
2017-03-20 10:21:44 +01:00
committed by wing328
parent 7ab746d355
commit 580745ef43
99 changed files with 11204 additions and 27 deletions

View File

@@ -31,6 +31,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
private static final String NET45 = "v4.5";
private static final String NET35 = "v3.5";
private static final String NETSTANDARD = "v5.0";
private static final String UWP = "uwp";
private static final String DATA_TYPE_WITH_ENUM_EXTENSION = "plainDatatypeWithEnum";
@@ -44,6 +45,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
protected String targetFrameworkNuget = "net45";
protected boolean supportsAsync = Boolean.TRUE;
protected boolean supportsUWP = Boolean.FALSE;
protected boolean netStandard = Boolean.FALSE;
protected boolean generatePropertyChanged = Boolean.FALSE;
protected Map<Character, String> regexModifiers;
protected final Map<String, String> frameworks;
@@ -89,6 +91,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
frameworks = new ImmutableMap.Builder<String, String>()
.put(NET35, ".NET Framework 3.5 compatible")
.put(NET45, ".NET Framework 4.5+ compatible")
.put(NETSTANDARD, ".NET Standard 1.3 compatible")
.put(UWP, "Universal Windows Platform - beta support")
.build();
framework.defaultValue(this.targetFramework);
@@ -202,6 +205,22 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
if(additionalProperties.containsKey("supportsAsync")){
additionalProperties.remove("supportsAsync");
}
} else if (NETSTANDARD.equals(this.targetFramework)){
setTargetFrameworkNuget("netstandard1.3");
setSupportsAsync(Boolean.TRUE);
setSupportsUWP(Boolean.FALSE);
setNetStandard(Boolean.TRUE);
additionalProperties.put("supportsAsync", this.supportsUWP);
additionalProperties.put("supportsUWP", this.supportsAsync);
additionalProperties.put("netStandard", this.netStandard);
//Tests not yet implemented for .NET Standard codegen
//Todo implement it
excludeTests = true;
if(additionalProperties.containsKey(CodegenConstants.EXCLUDE_TESTS)){
additionalProperties.remove(CodegenConstants.EXCLUDE_TESTS);
}
additionalProperties.put(CodegenConstants.EXCLUDE_TESTS, excludeTests);
} else if (UWP.equals(this.targetFramework)){
setTargetFrameworkNuget("uwp");
setSupportsAsync(Boolean.TRUE);
@@ -218,6 +237,8 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
if(additionalProperties.containsKey(CodegenConstants.GENERATE_PROPERTY_CHANGED)) {
if(NET35.equals(targetFramework)) {
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 {
setGeneratePropertyChanged(Boolean.valueOf(additionalProperties.get(CodegenConstants.GENERATE_PROPERTY_CHANGED).toString()));
}
@@ -282,14 +303,17 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
clientPackageDir, "ApiResponse.cs"));
supportingFiles.add(new SupportingFile("ExceptionFactory.mustache",
clientPackageDir, "ExceptionFactory.cs"));
if(Boolean.FALSE.equals(this.netStandard)) {
supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat"));
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh"));
supportingFiles.add(new SupportingFile("compile.mustache", "", "build.bat"));
supportingFiles.add(new SupportingFile("compile-mono.sh.mustache", "", "build.sh"));
// copy package.config to nuget's standard location for project-level installs
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"));
// copy package.config to nuget's standard location for project-level installs
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 {
supportingFiles.add(new SupportingFile("project.json.mustache", packageFolder + File.separator, "project.json"));
}
// Only write out test related files if excludeTests is unset or explicitly set to false (see start of this method)
if(Boolean.FALSE.equals(excludeTests)) {
@@ -319,7 +343,9 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
if (optionalProjectFileFlag) {
supportingFiles.add(new SupportingFile("Solution.mustache", "", packageName + ".sln"));
supportingFiles.add(new SupportingFile("Project.mustache", packageFolder, packageName + ".csproj"));
supportingFiles.add(new SupportingFile("nuspec.mustache", packageFolder, packageName + ".nuspec"));
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.
@@ -574,6 +600,10 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
this.supportsUWP = supportsUWP;
}
public void setNetStandard(Boolean netStandard){
this.netStandard = netStandard;
}
public void setGeneratePropertyChanged(final Boolean generatePropertyChanged){
this.generatePropertyChanged = generatePropertyChanged;
}