Skip to content

Commit 210c374

Browse files
wing328iquirinoBouillieOlivier Leonard
authored andcommitted
[C#] dependency upgrade (OpenAPITools#5870)
* Updating packages version (OpenAPITools#5313) * Add support to RestSharp version 106.10.1 Restsharp 106.10.1 needs the Content Lenght as a parameter to AddFile method * Updating RestSharp Version Updating RestSharp Version * Update netcore_project.mustache * Update netcore_testproject.mustache * Update Project.mustache * Updating packages version Updating packages version * Updating packages version Updating packages version * Updating packages version Updating packages version * Updating packages version Updating packages version * Updating packages version Updating packages version * Updating packages version Updating packages version * Execute task async obsolete Use ExecuteAsync instead * update csharp samples Co-authored-by: William Cheng <[email protected]> * [csharp] Library upgrade fix (OpenAPITools#5848) * On .net45 framework, Restsharp version is updated to 106.10.1 Otherwise, it stays on version 105.1.0 * Added additionalProperties for library versions and target frameworks * Removed unused properties * Added an additional property to test for a specific version of RestSharp * Updated csharp samples * Fixed nuspec.mustache to use library specific additional properties * Updated csharp samples * Updating CI/samples.ci csharp petstore test project file. * Updated csharp.md Co-authored-by: Olivier Leonard <[email protected]> * [csharp-client] Restored tests on csharp samples (OpenAPITools#5879) * Restored tests on csharp samples * Restored a reference to the file used to test file uploads Co-authored-by: Olivier Leonard <[email protected]> * update samples Co-authored-by: Igor Quirino <[email protected]> Co-authored-by: Bouillie <[email protected]> Co-authored-by: Olivier Leonard <[email protected]>
1 parent 66deff6 commit 210c374

File tree

52 files changed

+300
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+300
-222
lines changed

CI/samples.ci/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools.Test/Org.OpenAPITools.Test.csproj

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ OpenAPI Petstore
44
55
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
66
7-
OpenAPI spec version: 1.0.0
7+
The version of the OpenAPI document: 1.0.0
88
99
-->
1010
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
@@ -47,16 +47,16 @@ OpenAPI spec version: 1.0.0
4747
<Reference Include="System.Runtime.Serialization" />
4848
<Reference Include="System.Xml" />
4949
<Reference Include="Newtonsoft.Json">
50-
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
51-
<HintPath Condition="Exists('..\packages')">..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
52-
<HintPath Condition="Exists('..\..\packages')">..\..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
53-
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
50+
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
51+
<HintPath Condition="Exists('..\packages')">..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
52+
<HintPath Condition="Exists('..\..\packages')">..\..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
53+
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
5454
</Reference>
5555
<Reference Include="JsonSubTypes">
56-
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\JsonSubTypes.1.5.2\lib\net45\JsonSubTypes.dll</HintPath>
57-
<HintPath Condition="Exists('..\packages')">..\packages\JsonSubTypes.1.5.2\lib\net45\JsonSubTypes.dll</HintPath>
58-
<HintPath Condition="Exists('..\..\packages')">..\..\packages\JsonSubTypes.1.5.2\lib\net45\JsonSubTypes.dll</HintPath>
59-
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\JsonSubTypes.1.5.2\lib\net45\JsonSubTypes.dll</HintPath>
56+
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\JsonSubTypes.1.6.0\lib\net45\JsonSubTypes.dll</HintPath>
57+
<HintPath Condition="Exists('..\packages')">..\packages\JsonSubTypes.1.6.0\lib\net45\JsonSubTypes.dll</HintPath>
58+
<HintPath Condition="Exists('..\..\packages')">..\..\packages\JsonSubTypes.1.6.0\lib\net45\JsonSubTypes.dll</HintPath>
59+
<HintPath Condition="Exists('..\..\vendor')">..\..\vendor\JsonSubTypes.1.6.0\lib\net45\JsonSubTypes.dll</HintPath>
6060
</Reference>
6161
<Reference Include="RestSharp">
6262
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\RestSharp.105.1.0\lib\net45\RestSharp.dll</HintPath>
@@ -72,7 +72,8 @@ OpenAPI spec version: 1.0.0
7272
</Reference>
7373
</ItemGroup>
7474
<ItemGroup>
75-
<Compile Include="**\*.cs" Exclude="obj\**" />
75+
<Compile Include="**\*.cs"
76+
Exclude="obj\**"/>
7677
</ItemGroup>
7778
<ItemGroup>
7879
<None Include="packages.config" />

docs/generators/csharp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sidebar_label: csharp
2323
|returnICollection|Return ICollection&lt;T&gt; instead of the concrete type.| |false|
2424
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
2525
|sourceFolder|source folder for generated code| |src|
26-
|targetFramework|The target .NET framework version.|<dl><dt>**v3.5**</dt><dd>.NET Framework 3.5 compatible</dd><dt>**v4.0**</dt><dd>.NET Framework 4.0 compatible</dd><dt>**v4.5**</dt><dd>.NET Framework 4.5+ compatible</dd><dt>**v5.0**</dt><dd>.NET Standard 1.3 compatible (DEPRECATED. Please use `csharp-netcore` generator instead)</dd><dt>**uwp**</dt><dd>Universal Windows Platform (DEPRECATED. Please use `csharp-netcore` generator instead)</dd></dl>|v4.5|
26+
|targetFramework|The target .NET framework version.|<dl><dt>**v3.5**</dt><dd>.NET Framework 3.5 compatible</dd><dt>**v4.0**</dt><dd>.NET Framework 4.0 compatible</dd><dt>**v4.5**</dt><dd>.NET Framework 4.5 compatible</dd><dt>**v4.5.2**</dt><dd>.NET Framework 4.5.2+ compatible</dd><dt>**v5.0**</dt><dd>.NET Standard 1.3 compatible (DEPRECATED. Please use `csharp-netcore` generator instead)</dd><dt>**uwp**</dt><dd>Universal Windows Platform (DEPRECATED. Please use `csharp-netcore` generator instead)</dd></dl>|v4.5|
2727
|useCollection|Deserialize array types to Collection&lt;T&gt; instead of List&lt;T&gt;.| |false|
2828
|useCompareNetObjects|Use KellermanSoftware.CompareNetObjects for deep recursive object comparison. WARNING: this option incurs potential performance impact.| |false|
2929
|useDateTimeOffset|Use DateTimeOffset to model date-time properties| |false|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
public class CSharpClientCodegen extends AbstractCSharpCodegen {
3838
@SuppressWarnings({"hiding"})
3939
private static final Logger LOGGER = LoggerFactory.getLogger(CSharpClientCodegen.class);
40+
private static final String NUNIT = "nunit";
41+
private static final String RESTSHARP = "restsharp";
42+
private static final String NEWTONSOFT_JSON = "newtonsoft-json";
43+
private static final String JSON_SUBTYPES = "json-subtypes";
44+
private static final String FODY = "fody";
45+
private static final String PROPERTYCHANGED_FODY = "propertychanged-fody";
46+
private static final String NET452 = "v4.5.2";
4047
private static final String NET45 = "v4.5";
4148
private static final String NET40 = "v4.0";
4249
private static final String NET35 = "v3.5";
@@ -158,7 +165,8 @@ public CSharpClientCodegen() {
158165
frameworks = new ImmutableMap.Builder<String, String>()
159166
.put(NET35, ".NET Framework 3.5 compatible")
160167
.put(NET40, ".NET Framework 4.0 compatible")
161-
.put(NET45, ".NET Framework 4.5+ compatible")
168+
.put(NET45, ".NET Framework 4.5 compatible")
169+
.put(NET452, ".NET Framework 4.5.2+ compatible")
162170
.put(NETSTANDARD, ".NET Standard 1.3 compatible (DEPRECATED. Please use `csharp-netcore` generator instead)")
163171
.put(UWP, "Universal Windows Platform (DEPRECATED. Please use `csharp-netcore` generator instead)")
164172
.build();
@@ -328,15 +336,17 @@ public void processOpts() {
328336
setSupportsUWP(Boolean.TRUE);
329337
} else if (NET40.equals(this.targetFramework)) {
330338
additionalProperties.put(MCS_NET_VERSION_KEY, "4");
331-
additionalProperties.put("isNet40", true);
332-
333339
if (additionalProperties.containsKey(CodegenConstants.SUPPORTS_ASYNC)) {
334340
LOGGER.warn(".NET " + NET40 + " generator does not support async.");
335341
additionalProperties.remove(CodegenConstants.SUPPORTS_ASYNC);
336342
}
337343

338344
setTargetFrameworkNuget("net40");
339345
setSupportsAsync(Boolean.FALSE);
346+
} else if (NET452.equals(this.targetFramework)) {
347+
additionalProperties.put(MCS_NET_VERSION_KEY, "4.5.2-api");
348+
setTargetFrameworkNuget("net452");
349+
setSupportsAsync(Boolean.TRUE);
340350
} else {
341351
additionalProperties.put(MCS_NET_VERSION_KEY, "4.5.2-api");
342352
setTargetFrameworkNuget("net45");
@@ -706,6 +716,46 @@ public void setTargetFramework(String dotnetFramework) {
706716
} else {
707717
this.targetFramework = dotnetFramework;
708718
}
719+
switch (targetFramework) {
720+
case NET35:
721+
additionalProperties.put(RESTSHARP, new LibraryDependency("105.1.0", "net35"));
722+
additionalProperties.put(JSON_SUBTYPES, new LibraryDependency("1.6.0", "net35"));
723+
additionalProperties.put(NEWTONSOFT_JSON, new LibraryDependency("12.0.3", "net35"));
724+
additionalProperties.put(NUNIT, new LibraryDependency("3.11.0", "net35"));
725+
break;
726+
case NET40:
727+
additionalProperties.put(RESTSHARP, new LibraryDependency("105.1.0", "net4"));
728+
additionalProperties.put(JSON_SUBTYPES, new LibraryDependency("1.6.0", "net40"));
729+
additionalProperties.put(NEWTONSOFT_JSON, new LibraryDependency("12.0.3", "net40"));
730+
additionalProperties.put(NUNIT, new LibraryDependency("3.11.0", "net40"));
731+
break;
732+
case NET45:
733+
additionalProperties.put(RESTSHARP, new LibraryDependency("105.1.0", "net45"));
734+
additionalProperties.put(JSON_SUBTYPES, new LibraryDependency("1.6.0", "net45"));
735+
additionalProperties.put(NEWTONSOFT_JSON, new LibraryDependency("12.0.3", "net45"));
736+
additionalProperties.put(NUNIT, new LibraryDependency("3.11.0", "net45"));
737+
break;
738+
case NET452:
739+
additionalProperties.put(RESTSHARP, new LibraryDependency("106.10.1", "net452"));
740+
additionalProperties.put(JSON_SUBTYPES, new LibraryDependency("1.6.0", "net45"));
741+
additionalProperties.put(NEWTONSOFT_JSON, new LibraryDependency("12.0.3", "net45"));
742+
additionalProperties.put(NUNIT, new LibraryDependency("3.11.0", "net45"));
743+
additionalProperties.put("isRestSharp_106_10_1_above", true);
744+
break;
745+
case UWP:
746+
additionalProperties.put(RESTSHARP, new LibraryDependency("105.1.0", "uwp"));
747+
additionalProperties.put(JSON_SUBTYPES, new LibraryDependency("1.6.0", "uwp"));
748+
additionalProperties.put(NEWTONSOFT_JSON, new LibraryDependency("12.0.3", "uwp"));
749+
additionalProperties.put(NUNIT, new LibraryDependency("3.11.0", "uwp"));
750+
break;
751+
case NETSTANDARD:
752+
additionalProperties.put(RESTSHARP, new LibraryDependency("105.1.0", "netstandard1.3"));
753+
additionalProperties.put(JSON_SUBTYPES, new LibraryDependency("1.6.0", "netstandard1.3"));
754+
additionalProperties.put(NEWTONSOFT_JSON, new LibraryDependency("12.0.3", "netstandard1.3"));
755+
additionalProperties.put(NUNIT, new LibraryDependency("3.11.0", "netstandard1.3"));
756+
break;
757+
}
758+
709759
LOGGER.info("Generating code for .NET Framework " + this.targetFramework);
710760
}
711761

@@ -854,6 +904,10 @@ public void setNetStandard(Boolean netStandard) {
854904

855905
public void setGeneratePropertyChanged(final Boolean generatePropertyChanged) {
856906
this.generatePropertyChanged = generatePropertyChanged;
907+
if (this.generatePropertyChanged) {
908+
additionalProperties.put(FODY, new LibraryDependency("1.29.4", targetFrameworkNuget));
909+
additionalProperties.put(PROPERTYCHANGED_FODY, new LibraryDependency("1.51.3", targetFrameworkNuget));
910+
}
857911
}
858912

859913
public void setUseCompareNetObjects(final Boolean useCompareNetObjects) {
@@ -945,3 +999,13 @@ public String getNullableType(Schema p, String type) {
945999
}
9461000

9471001
}
1002+
1003+
class LibraryDependency {
1004+
String version;
1005+
String targetFramework;
1006+
1007+
public LibraryDependency(String version, String targetFramework) {
1008+
this.version = version;
1009+
this.targetFramework = targetFramework;
1010+
}
1011+
}

modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace {{packageName}}.Client
153153
{{/netStandard}}
154154
{{^netStandard}}
155155
{{^supportsUWP}}
156-
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
156+
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName{{#isRestSharp_106_10_1_above}}, param.Value.ContentLength{{/isRestSharp_106_10_1_above}}, param.Value.ContentType);
157157
{{/supportsUWP}}
158158
{{#supportsUWP}}
159159
byte[] paramWriter = null;
@@ -565,6 +565,7 @@ namespace {{packageName}}.Client
565565
/// Convert params to key/value pairs.
566566
/// Use collectionFormat to properly format lists and collections.
567567
/// </summary>
568+
/// <param name="collectionFormat">Collection format.</param>
568569
/// <param name="name">Key name.</param>
569570
/// <param name="value">Value object.</param>
570571
/// <returns>A list of KeyValuePairs</returns>

modules/openapi-generator/src/main/resources/csharp/Project.mustache

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,26 +69,26 @@
6969
<Reference Include="System.Runtime.Serialization" />
7070
<Reference Include="System.Xml" />
7171
<Reference Include="Newtonsoft.Json">
72-
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\Newtonsoft.Json.12.0.1\lib\{{targetFrameworkNuget}}\Newtonsoft.Json.dll</HintPath>
73-
<HintPath Condition="Exists('..\packages')">..\packages\Newtonsoft.Json.12.0.1\lib\{{targetFrameworkNuget}}\Newtonsoft.Json.dll</HintPath>
74-
<HintPath Condition="Exists('..\..\packages')">..\..\packages\Newtonsoft.Json.12.0.1\lib\{{targetFrameworkNuget}}\Newtonsoft.Json.dll</HintPath>
75-
<HintPath Condition="Exists('{{binRelativePath}}')">{{binRelativePath}}\Newtonsoft.Json.12.0.1\lib\{{targetFrameworkNuget}}\Newtonsoft.Json.dll</HintPath>
72+
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\Newtonsoft.Json.{{newtonsoft-json.version}}\lib\{{newtonsoft-json.targetFramework}}\Newtonsoft.Json.dll</HintPath>
73+
<HintPath Condition="Exists('..\packages')">..\packages\Newtonsoft.Json.{{newtonsoft-json.version}}\lib\{{newtonsoft-json.targetFramework}}\Newtonsoft.Json.dll</HintPath>
74+
<HintPath Condition="Exists('..\..\packages')">..\..\packages\Newtonsoft.Json.{{newtonsoft-json.version}}\lib\{{newtonsoft-json.targetFramework}}\Newtonsoft.Json.dll</HintPath>
75+
<HintPath Condition="Exists('{{binRelativePath}}')">{{binRelativePath}}\Newtonsoft.Json.{{newtonsoft-json.version}}\lib\{{newtonsoft-json.targetFramework}}\Newtonsoft.Json.dll</HintPath>
7676
</Reference>
7777
<Reference Include="JsonSubTypes">
78-
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\JsonSubTypes.1.5.2\lib\{{targetFrameworkNuget}}\JsonSubTypes.dll</HintPath>
79-
<HintPath Condition="Exists('..\packages')">..\packages\JsonSubTypes.1.5.2\lib\{{targetFrameworkNuget}}\JsonSubTypes.dll</HintPath>
80-
<HintPath Condition="Exists('..\..\packages')">..\..\packages\JsonSubTypes.1.5.2\lib\{{targetFrameworkNuget}}\JsonSubTypes.dll</HintPath>
81-
<HintPath Condition="Exists('{{binRelativePath}}')">{{binRelativePath}}\JsonSubTypes.1.5.2\lib\{{targetFrameworkNuget}}\JsonSubTypes.dll</HintPath>
78+
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\JsonSubTypes.{{json-subtypes.version}}\lib\{{json-subtypes.targetFramework}}\JsonSubTypes.dll</HintPath>
79+
<HintPath Condition="Exists('..\packages')">..\packages\JsonSubTypes.{{json-subtypes.version}}\lib\{{json-subtypes.targetFramework}}\JsonSubTypes.dll</HintPath>
80+
<HintPath Condition="Exists('..\..\packages')">..\..\packages\JsonSubTypes.{{json-subtypes.version}}\lib\{{json-subtypes.targetFramework}}\JsonSubTypes.dll</HintPath>
81+
<HintPath Condition="Exists('{{binRelativePath}}')">{{binRelativePath}}\JsonSubTypes.{{json-subtypes.version}}\lib\{{json-subtypes.targetFramework}}\JsonSubTypes.dll</HintPath>
8282
</Reference>
8383
<Reference Include="RestSharp">
84-
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll</HintPath>
85-
<HintPath Condition="Exists('..\packages')">..\packages\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll</HintPath>
86-
<HintPath Condition="Exists('..\..\packages')">..\..\packages\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll</HintPath>
87-
<HintPath Condition="Exists('{{binRelativePath}}')">{{binRelativePath}}\RestSharp.105.1.0\lib\{{#isNet40}}net4{{/isNet40}}{{^isNet40}}{{targetFrameworkNuget}}{{/isNet40}}\RestSharp.dll</HintPath>
84+
<HintPath Condition="Exists('$(SolutionDir)\packages')">$(SolutionDir)\packages\RestSharp.{{restsharp.version}}\lib\{{restsharp.targetFramework}}\RestSharp.dll</HintPath>
85+
<HintPath Condition="Exists('..\packages')">..\packages\RestSharp.{{restsharp.version}}\lib\{{restsharp.targetFramework}}\RestSharp.dll</HintPath>
86+
<HintPath Condition="Exists('..\..\packages')">..\..\packages\RestSharp.{{restsharp.version}}\lib\{{restsharp.targetFramework}}\RestSharp.dll</HintPath>
87+
<HintPath Condition="Exists('{{binRelativePath}}')">{{binRelativePath}}\RestSharp.{{restsharp.version}}\lib\{{restsharp.targetFramework}}\RestSharp.dll</HintPath>
8888
</Reference>
8989
{{#generatePropertyChanged}}
9090
<Reference Include="PropertyChanged">
91-
<HintPath>..\..\packages\PropertyChanged.Fody.1.51.3\Lib\portable-net4+sl4+wp8+win8+wpa81+MonoAndroid16+MonoTouch40\PropertyChanged.dll</HintPath>
91+
<HintPath>..\..\packages\PropertyChanged.Fody.{{propertychanged-fody.version}}\Lib\portable-net4+sl4+wp8+win8+wpa81+MonoAndroid16+MonoTouch40\PropertyChanged.dll</HintPath>
9292
</Reference>
9393
{{/generatePropertyChanged}}
9494
{{/netStandard}}
@@ -110,7 +110,7 @@
110110
</ItemGroup>
111111
<Import Project="$(MsBuildToolsPath)\Microsoft.CSharp.targets" />
112112
{{#generatePropertyChanged}}
113-
<Import Project="..\..\packages\Fody.1.29.4\build\portable-net+sl+win+wpa+wp\Fody.targets" Condition="Exists('..\..\packages\Fody.1.29.4\build\portable-net+sl+win+wpa+wp\Fody.targets')" />
113+
<Import Project="..\..\packages\Fody.{{fody.version}}\build\portable-net+sl+win+wpa+wp\Fody.targets" Condition="Exists('..\..\packages\Fody.{{fody.version}}\build\portable-net+sl+win+wpa+wp\Fody.targets')" />
114114
{{/generatePropertyChanged}}
115115
{{/netStandard}}
116116
{{#netStandard}}

0 commit comments

Comments
 (0)