diff --git a/docs/generators/csharp-netcore.md b/docs/generators/csharp-netcore.md index 7b67601f3d3c..8cf2d0ee54ad 100644 --- a/docs/generators/csharp-netcore.md +++ b/docs/generators/csharp-netcore.md @@ -25,7 +25,7 @@ sidebar_label: csharp-netcore |returnICollection|Return ICollection<T> instead of the concrete type.| |false| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| |sourceFolder|source folder for generated code| |src| -|targetFramework|The target .NET framework version.|
**netstandard1.3**
.NET Standard 1.3 compatible
**netstandard1.4**
.NET Standard 1.4 compatible
**netstandard1.5**
.NET Standard 1.5 compatible
**netstandard1.6**
.NET Standard 1.6 compatible
**netstandard2.0**
.NET Standard 2.0 compatible
**netcoreapp2.0**
.NET Core 2.0 compatible
|netstandard2.0| +|targetFramework|The target .NET framework version.|
**netstandard1.3**
.NET Standard 1.3 compatible
**netstandard1.4**
.NET Standard 1.4 compatible
**netstandard1.5**
.NET Standard 1.5 compatible
**netstandard1.6**
.NET Standard 1.6 compatible
**netstandard2.0**
.NET Standard 2.0 compatible
**netstandard2.1**
.NET Standard 2.1 compatible
**netcoreapp2.0**
.NET Core 2.0 compatible
**netcoreapp2.1**
.NET Core 2.1 compatible
**netcoreapp3.0**
.NET Core 3.0 compatible
**netcoreapp3.1**
.NET Core 3.1 compatible
|netstandard2.0| |useCollection|Deserialize array types to Collection<T> instead of List<T>.| |false| |useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false| |validatable|Generates self-validatable models.| |true| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java index f17168d19d78..95ced94f2f8e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpNetCoreClientCodegen.java @@ -56,7 +56,11 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen { FrameworkStrategy.NETSTANDARD_1_5, FrameworkStrategy.NETSTANDARD_1_6, FrameworkStrategy.NETSTANDARD_2_0, - FrameworkStrategy.NETCOREAPP_2_0 + FrameworkStrategy.NETSTANDARD_2_1, + FrameworkStrategy.NETCOREAPP_2_0, + FrameworkStrategy.NETCOREAPP_2_1, + FrameworkStrategy.NETCOREAPP_3_0, + FrameworkStrategy.NETCOREAPP_3_1 ); private static FrameworkStrategy defaultFramework = FrameworkStrategy.NETSTANDARD_2_0; protected final Map frameworks; @@ -67,6 +71,7 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen { // Defines TargetFrameworkVersion in csproj files protected String targetFramework = defaultFramework.name; + protected String testTargetFramework = defaultFramework.testTargetFramework; // Defines nuget identifiers for target framework protected String targetFrameworkNuget = targetFramework; @@ -548,6 +553,7 @@ public void processOpts() { setTargetFrameworkNuget(strategy.getNugetFrameworkIdentifier()); setTargetFramework(strategy.name); + setTestTargetFramework(strategy.testTargetFramework); if (strategy != FrameworkStrategy.NETSTANDARD_2_0) { LOGGER.warn("If using built-in templates-RestSharp only supports netstandard 2.0 or later."); @@ -571,6 +577,7 @@ public void processOpts() { syncStringProperty(additionalProperties, CodegenConstants.MODEL_PACKAGE, this::setModelPackage, modelPackage); syncStringProperty(additionalProperties, CodegenConstants.OPTIONAL_PROJECT_GUID, this::setPackageGuid, packageGuid); syncStringProperty(additionalProperties, "targetFrameworkNuget", this::setTargetFrameworkNuget, this.targetFrameworkNuget); + syncStringProperty(additionalProperties, "testTargetFramework", this::setTestTargetFramework, this.testTargetFramework); syncBooleanProperty(additionalProperties, "netStandard", this::setNetStandard, this.netStandard); @@ -702,6 +709,10 @@ public void setTargetFramework(String dotnetFramework) { LOGGER.info("Generating code for .NET Framework " + this.targetFramework); } + public void setTestTargetFramework(String testTargetFramework) { + this.testTargetFramework = testTargetFramework; + } + public void setTargetFrameworkNuget(String targetFrameworkNuget) { this.targetFrameworkNuget = targetFrameworkNuget; } @@ -854,34 +865,41 @@ private void syncStringProperty(final Map additionalProperties, // https://docs.microsoft.com/en-us/dotnet/standard/net-standard @SuppressWarnings("Duplicates") private static abstract class FrameworkStrategy { - static FrameworkStrategy NETSTANDARD_1_3 = new FrameworkStrategy("netstandard1.3", ".NET Standard 1.3 compatible", "v4.6.1") { + static FrameworkStrategy NETSTANDARD_1_3 = new FrameworkStrategy("netstandard1.3", ".NET Standard 1.3 compatible", "netcoreapp2.0") { }; - static FrameworkStrategy NETSTANDARD_1_4 = new FrameworkStrategy("netstandard1.4", ".NET Standard 1.4 compatible", "v4.6.1") { + static FrameworkStrategy NETSTANDARD_1_4 = new FrameworkStrategy("netstandard1.4", ".NET Standard 1.4 compatible", "netcoreapp2.0") { }; - static FrameworkStrategy NETSTANDARD_1_5 = new FrameworkStrategy("netstandard1.5", ".NET Standard 1.5 compatible", "v4.6.1") { + static FrameworkStrategy NETSTANDARD_1_5 = new FrameworkStrategy("netstandard1.5", ".NET Standard 1.5 compatible", "netcoreapp2.0") { }; - static FrameworkStrategy NETSTANDARD_1_6 = new FrameworkStrategy("netstandard1.6", ".NET Standard 1.6 compatible", "v4.6.1") { + static FrameworkStrategy NETSTANDARD_1_6 = new FrameworkStrategy("netstandard1.6", ".NET Standard 1.6 compatible", "netcoreapp2.0") { }; - static FrameworkStrategy NETSTANDARD_2_0 = new FrameworkStrategy("netstandard2.0", ".NET Standard 2.0 compatible", "v4.6.1") { + static FrameworkStrategy NETSTANDARD_2_0 = new FrameworkStrategy("netstandard2.0", ".NET Standard 2.0 compatible", "netcoreapp2.0") { }; - static FrameworkStrategy NETCOREAPP_2_0 = new FrameworkStrategy("netcoreapp2.0", ".NET Core 2.0 compatible", "v4.6.1", Boolean.FALSE) { - + static FrameworkStrategy NETSTANDARD_2_1 = new FrameworkStrategy("netstandard2.1", ".NET Standard 2.1 compatible", "netcoreapp3.0") { + }; + static FrameworkStrategy NETCOREAPP_2_0 = new FrameworkStrategy("netcoreapp2.0", ".NET Core 2.0 compatible", "netcoreapp2.0", Boolean.FALSE) { + }; + static FrameworkStrategy NETCOREAPP_2_1 = new FrameworkStrategy("netcoreapp2.1", ".NET Core 2.1 compatible", "netcoreapp2.1", Boolean.FALSE) { + }; + static FrameworkStrategy NETCOREAPP_3_0 = new FrameworkStrategy("netcoreapp3.0", ".NET Core 3.0 compatible", "netcoreapp3.0", Boolean.FALSE) { + }; + static FrameworkStrategy NETCOREAPP_3_1 = new FrameworkStrategy("netcoreapp3.1", ".NET Core 3.1 compatible", "netcoreapp3.1", Boolean.FALSE) { }; protected String name; protected String description; - protected String dotNetFrameworkVersion; + protected String testTargetFramework; private Boolean isNetStandard = Boolean.TRUE; - FrameworkStrategy(String name, String description, String dotNetFrameworkVersion) { + FrameworkStrategy(String name, String description, String testTargetFramework) { this.name = name; this.description = description; - this.dotNetFrameworkVersion = dotNetFrameworkVersion; + this.testTargetFramework = testTargetFramework; } - FrameworkStrategy(String name, String description, String dotNetFrameworkVersion, Boolean isNetStandard) { + FrameworkStrategy(String name, String description, String testTargetFramework, Boolean isNetStandard) { this.name = name; this.description = description; - this.dotNetFrameworkVersion = dotNetFrameworkVersion; + this.testTargetFramework = testTargetFramework; this.isNetStandard = isNetStandard; } diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/TestProject.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/TestProject.mustache index 9ef7ae726ae9..a5d124698075 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/TestProject.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/TestProject.mustache @@ -17,8 +17,7 @@ Properties {{testPackageName}} {{testPackageName}} - - netcoreapp2.0 + {{testTargetFramework}} false 512 diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/netcore_testproject.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/netcore_testproject.mustache index aa4f8beb8b03..d6faf0b43f97 100644 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/netcore_testproject.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/netcore_testproject.mustache @@ -13,7 +13,7 @@ true true {{testPackageName}} - netcoreapp2.0 + {{testTargetFramework}} false