Skip to content

Commit fc2827d

Browse files
committed
Support multi targetting
1 parent 5cffc45 commit fc2827d

99 files changed

Lines changed: 937 additions & 504 deletions

File tree

Some content is hidden

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

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

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,74 @@
3636
<PackageReference Include="RestSharp" Version="112.0.0" />
3737
{{/useRestSharp}}
3838
{{#useGenericHost}}
39-
<PackageReference Include="Microsoft.Extensions.Http" Version="{{#lambda.first}}{{#netStandard}}5.0.0 {{/netStandard}}{{#net47}}7.0.0 {{/net47}}{{#net48}}7.0.0 {{/net48}}{{#net6.0}}6.0.0 {{/net6.0}}{{#net7.0}}7.0.0 {{/net7.0}}{{#net8.0}}8.0.1 {{/net8.0}}{{#net9.0}}9.0.5 {{/net9.0}}{{#net10.0}}10.0.1 {{/net10.0}}{{/lambda.first}}" />
40-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="{{#lambda.first}}{{#netStandard}}5.0.0 {{/netStandard}}{{#net47}}7.0.0 {{/net47}}{{#net48}}7.0.0 {{/net48}}{{#net6.0}}6.0.1 {{/net6.0}}{{#net7.0}}7.0.1 {{/net7.0}}{{#net8.0}}8.0.1 {{/net8.0}}{{#net9.0}}9.0.5 {{/net9.0}}{{#net10.0}}10.0.1 {{/net10.0}}{{/lambda.first}}" />
39+
{{#netStandard}}
40+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard1.4' or '$(TargetFramework)' == 'netstandard1.5' or '$(TargetFramework)' == 'netstandard1.6' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'" Version="6.0.1" />
41+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard1.4' or '$(TargetFramework)' == 'netstandard1.5' or '$(TargetFramework)' == 'netstandard1.6' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'" Version="6.0.1" />
42+
{{/netStandard}}
43+
{{#net47}}
44+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net47' or '$(TargetFramework)' == 'net471' or '$(TargetFramework)' == 'net472'" Version="7.0.0" />
45+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net47' or '$(TargetFramework)' == 'net471' or '$(TargetFramework)' == 'net472'" Version="7.0.0" />
46+
{{/net47}}
47+
{{#net48}}
48+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net48' or '$(TargetFramework)' == 'net481'" Version="7.0.0" />
49+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net48' or '$(TargetFramework)' == 'net481'" Version="7.0.0" />
50+
{{/net48}}
51+
{{#net6.0}}
52+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net6.0'" Version="6.0.1" />
53+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net6.0'" Version="6.0.1" />
54+
{{/net6.0}}
55+
{{#net7.0}}
56+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net7.0'" Version=7.0.1" />
57+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net7.0'" Version="7.0.1" />
58+
{{/net7.0}}
59+
{{#net8.0}}
60+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net8.0'" Version="8.0.1" />
61+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net8.0'" Version="8.0.1" />
62+
{{/net8.0}}
63+
{{#net9.0}}
64+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.6" />
65+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.6" />
66+
{{/net9.0}}
67+
{{#net10.0}}
68+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
69+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
70+
{{/net10.0}}
4171
{{#supportsRetry}}
42-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="{{#lambda.first}}{{#netStandard}}5.0.1 {{/netStandard}}{{#net47}}7.0.0 {{/net47}}{{#net48}}7.0.0 {{/net48}}{{#net6.0}}6.0.19 {{/net6.0}}{{#net7.0}}7.0.11 {{/net7.0}}{{#net8.0}}8.0.8 {{/net8.0}}{{#net9.0}}9.0.5 {{/net9.0}}{{#net10.0}}10.0.1 {{/net10.0}}{{/lambda.first}}" />
72+
{{#netStandard}}
73+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'netstandard1.3' or '$(TargetFramework)' == 'netstandard1.4' or '$(TargetFramework)' == 'netstandard1.5' or '$(TargetFramework)' == 'netstandard1.6' or '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'" Version="5.0.1" />
74+
{{/netStandard}}
75+
{{#net47}}
76+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net47' or '$(TargetFramework)' == 'net471' or '$(TargetFramework)' == 'net472'" Version="7.0.0" />
77+
{{/net47}}
78+
{{#net48}}
79+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net48' or '$(TargetFramework)' == 'net481'" Version="7.0.0" />
80+
{{/net48}}
81+
{{#net6.0}}
82+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net6.0'" Version="6.0.36" />
83+
{{/net6.0}}
84+
{{#net7.0}}
85+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net7.0'" Version="7.0.20" />
86+
{{/net7.0}}
87+
{{#net8.0}}
88+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net8.0'" Version="8.0.20" />
89+
{{/net8.0}}
90+
{{#net9.0}}
91+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.6" />
92+
{{/net9.0}}
93+
{{#net10.0}}
94+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
95+
{{/net10.0}}
4396
{{/supportsRetry}}
4497
{{#net80OrLater}}
45-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="{{#lambda.first}}{{#net8.0}}8.0.8 {{/net8.0}}{{#net9.0}}9.0.5 {{/net9.0}}{{#net10.0}}10.0.1 {{/net10.0}}{{/lambda.first}}" />
98+
{{#net8.0}}
99+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net8.0'" Version="8.0.17" />
100+
{{/net8.0}}
101+
{{#net9.0}}
102+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.6" />
103+
{{/net9.0}}
104+
{{#net10.0}}
105+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
106+
{{/net10.0}}
46107
{{/net80OrLater}}
47108
{{^net60OrLater}}
48109
<PackageReference Include="System.Threading.Channels" Version="8.0.0" />

samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Org.OpenAPITools.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1 " />
26-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1 " />
27-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.1 " />
28-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="10.0.1 " />
25+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
26+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
27+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
28+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
2929
</ItemGroup>
3030

3131
</Project>

samples/client/petstore/csharp/generichost/latest/HelloWorld/src/Org.OpenAPITools/Org.OpenAPITools.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1 " />
26-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1 " />
27-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.1 " />
28-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="10.0.1 " />
25+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
26+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
27+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
28+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
2929
</ItemGroup>
3030

3131
</Project>

samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/src/Org.OpenAPITools/Org.OpenAPITools.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1 " />
26-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1 " />
27-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.1 " />
28-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="10.0.1 " />
25+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
26+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
27+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
28+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
2929
</ItemGroup>
3030

3131
</Project>

samples/client/petstore/csharp/generichost/latest/OneOfList/src/Org.OpenAPITools/Org.OpenAPITools.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1 " />
26-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1 " />
27-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.1 " />
28-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="10.0.1 " />
25+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
26+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
27+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
28+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
2929
</ItemGroup>
3030

3131
</Project>

samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Org.OpenAPITools.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1 " />
26-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1 " />
27-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.1 " />
28-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="10.0.1 " />
25+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
26+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
27+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
28+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
2929
</ItemGroup>
3030

3131
</Project>

samples/client/petstore/csharp/generichost/net10/AllOf/src/Org.OpenAPITools/Api/DefaultApi.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
using System;
1414
using System.Collections.Generic;
15+
using System.Collections.ObjectModel;
1516
using System.Net;
17+
using System.IO;
1618
using System.Threading.Tasks;
1719
using Microsoft.Extensions.Logging;
1820
using System.Net.Http;
@@ -247,10 +249,10 @@ public async Task<IListApiResponse> ListAsync(string personId, System.Threading.
247249
"application/json"
248250
};
249251

250-
string? acceptLocalVar = ClientUtils.SelectHeaderAccept(acceptLocalVars);
252+
IEnumerable<MediaTypeWithQualityHeaderValue> acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars);
251253

252-
if (acceptLocalVar != null)
253-
httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar));
254+
foreach (var acceptLocalVar in acceptHeaderValuesLocalVar)
255+
httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar);
254256

255257
httpRequestMessageLocalVar.Method = HttpMethod.Get;
256258

samples/client/petstore/csharp/generichost/net10/AllOf/src/Org.OpenAPITools/Client/ApiResponse`1.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public partial interface IApiResponse
5252
/// </summary>
5353
System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
5454

55+
/// <summary>
56+
/// The headers contained in the api response related to the content
57+
/// </summary>
58+
System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }
59+
5560
/// <summary>
5661
/// The path used when making the request.
5762
/// </summary>
@@ -109,6 +114,11 @@ public partial class ApiResponse : IApiResponse
109114
/// </summary>
110115
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
111116

117+
/// <summary>
118+
/// The headers contained in the api response related to the content
119+
/// </summary>
120+
public System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }
121+
112122
/// <summary>
113123
/// The DateTime when the request was retrieved.
114124
/// </summary>
@@ -147,6 +157,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
147157
{
148158
StatusCode = httpResponseMessage.StatusCode;
149159
Headers = httpResponseMessage.Headers;
160+
ContentHeaders = httpResponseMessage.Content.Headers;
150161
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
151162
ReasonPhrase = httpResponseMessage.ReasonPhrase;
152163
RawContent = rawContent;
@@ -170,6 +181,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
170181
{
171182
StatusCode = httpResponseMessage.StatusCode;
172183
Headers = httpResponseMessage.Headers;
184+
ContentHeaders = httpResponseMessage.Content.Headers;
173185
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
174186
ReasonPhrase = httpResponseMessage.ReasonPhrase;
175187
ContentStream = contentStream;
@@ -181,6 +193,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
181193
OnCreated(httpRequestMessage, httpResponseMessage);
182194
}
183195

196+
184197
partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
185198
}
186199

samples/client/petstore/csharp/generichost/net10/AllOf/src/Org.OpenAPITools/Client/ClientUtils.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using KellermanSoftware.CompareNetObjects;
2121
using Org.OpenAPITools.Model;
2222
using System.Runtime.CompilerServices;
23+
using System.Net.Http.Headers;
2324

2425
[assembly: InternalsVisibleTo("Org.OpenAPITools.Test")]
2526

@@ -235,6 +236,26 @@ public static byte[] ReadAsBytes(Stream inputStream)
235236
return string.Join(",", accepts);
236237
}
237238

239+
240+
241+
/// <summary>
242+
/// Select the Accept header's value from the given accepts array:
243+
/// if JSON exists in the given array, use it;
244+
/// otherwise use all of them.
245+
/// </summary>
246+
/// <param name="accepts">The accepts array to select from.</param>
247+
/// <returns>The Accept header values to use.</returns>
248+
public static IEnumerable<MediaTypeWithQualityHeaderValue> SelectHeaderAcceptArray(string[] accepts)
249+
{
250+
if (accepts.Length == 0)
251+
return [];
252+
253+
if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase))
254+
return [MediaTypeWithQualityHeaderValue.Parse("application/json")];
255+
256+
return accepts.Select(MediaTypeWithQualityHeaderValue.Parse);
257+
}
258+
238259
/// <summary>
239260
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
240261
/// </summary>

samples/client/petstore/csharp/generichost/net10/AllOf/src/Org.OpenAPITools/Org.OpenAPITools.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
<ItemGroup>
2525
<PackageReference Include="CompareNETObjects" Version="4.84.0" />
26-
<PackageReference Include="Microsoft.Extensions.Http" Version="10.0.1 " />
27-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1 " />
28-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="10.0.1 " />
29-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="10.0.1 " />
26+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
27+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
28+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
29+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net10.0'" Version="10.0.1" />
3030
</ItemGroup>
3131

3232
</Project>

0 commit comments

Comments
 (0)