Skip to content

Commit d21279e

Browse files
committed
feat: Improved generation for TargetFramework=net9.
1 parent fddf340 commit d21279e

File tree

10,699 files changed

+55322
-8417
lines changed

Some content is hidden

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

10,699 files changed

+55322
-8417
lines changed

src/libs/AutoSDK.SourceGenerators/AutoSDK.SourceGenerators.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<CompilerVisibleProperty Include="AutoSDK_UseRequiredKeyword"/>
2929
<!-- InSupportedTargetFrameworks/Never/Always. Default: InSupportedTargetFrameworks -->
3030
<CompilerVisibleProperty Include="AutoSDK_UseExperimentalAttributes"/>
31+
<!-- InSupportedTargetFrameworks/Never/Always. Default: InSupportedTargetFrameworks -->
32+
<CompilerVisibleProperty Include="AutoSDK_UseSetsRequiredMembersAttributes"/>
3133

3234
<!-- Methods generation -->
3335
<!-- true/false. Default: false -->

src/libs/AutoSDK.SourceGenerators/OptionsExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static Settings GetSettings(
3333
JsonSerializerType: options.GetEnumGlobalOption<JsonSerializerType>(nameof(Settings.JsonSerializerType), prefix),
3434
UseRequiredKeyword: options.GetEnumGlobalOption<SdkFeatureUsage>(nameof(Settings.UseRequiredKeyword), prefix),
3535
UseExperimentalAttributes: options.GetEnumGlobalOption<SdkFeatureUsage>(nameof(Settings.UseExperimentalAttributes), prefix),
36+
UseSetsRequiredMembersAttributes: options.GetEnumGlobalOption<SdkFeatureUsage>(nameof(Settings.UseSetsRequiredMembersAttributes), prefix),
3637

3738
GenerateConstructors: options.GetBoolGlobalOption(nameof(Settings.GenerateConstructors), prefix),
3839
GroupByTags: options.GetBoolGlobalOption(nameof(Settings.GroupByTags), prefix, defaultValue: true),

src/libs/AutoSDK/Models/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public readonly record struct Settings(
1313
JsonSerializerType JsonSerializerType,
1414
SdkFeatureUsage UseRequiredKeyword,
1515
SdkFeatureUsage UseExperimentalAttributes,
16+
SdkFeatureUsage UseSetsRequiredMembersAttributes,
1617

1718
bool GenerateConstructors,
1819
bool GroupByTags,
@@ -54,6 +55,7 @@ public readonly record struct Settings(
5455
JsonSerializerType: default,
5556
UseRequiredKeyword: default,
5657
UseExperimentalAttributes: default,
58+
UseSetsRequiredMembersAttributes: default,
5759
GenerateConstructors: false,
5860
GroupByTags: true,
5961
GenerateMethods: false,

src/libs/AutoSDK/Sources/Sources.Methods.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,9 @@ public partial interface I{endPoint.ClassName}
8181
}}".RemoveBlankLinesWhereOnlyWhitespaces();
8282
}
8383

84-
public static string GetHttpMethod(string targetFramework, OperationType operationType)
84+
public static string GetHttpMethod(OperationType operationType)
8585
{
86-
targetFramework = targetFramework ?? throw new ArgumentNullException(nameof(targetFramework));
87-
88-
if (operationType == OperationType.Patch// &&
89-
//(targetFramework.StartsWith("net4", StringComparison.OrdinalIgnoreCase) ||
90-
//targetFramework.StartsWith("netstandard", StringComparison.OrdinalIgnoreCase))
91-
)
86+
if (operationType == OperationType.Patch)
9287
{
9388
return "new global::System.Net.Http.HttpMethod(\"PATCH\")";
9489
}
@@ -138,7 +133,7 @@ public static string GenerateMethod(
138133
}};").Inject() : " ")}
139134
{GeneratePathAndQuery(endPoint)}
140135
using var __httpRequest = new global::System.Net.Http.HttpRequestMessage(
141-
method: {GetHttpMethod(endPoint.Settings.TargetFramework, endPoint.HttpMethod)},
136+
method: {GetHttpMethod(endPoint.HttpMethod)},
142137
requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute));
143138
#if NET6_0_OR_GREATER
144139
{ // Use HTTP/3.0 or HTTP/2.0 if available
@@ -349,9 +344,6 @@ public static string GenerateResponse(
349344
}
350345

351346
var jsonSerializer = endPoint.Settings.JsonSerializerType.GetSerializer();
352-
var cancellationTokenInsideReadAsync = endPoint.Settings.TargetFramework.StartsWith("net8", StringComparison.OrdinalIgnoreCase)
353-
? "cancellationToken"
354-
: string.Empty;
355347

356348
if (endPoint.Stream)
357349
{
@@ -374,7 +366,11 @@ public static string GenerateResponse(
374366
}};
375367
}}
376368
377-
using var __stream = await __response.Content.ReadAsStreamAsync({cancellationTokenInsideReadAsync}).ConfigureAwait(false);
369+
using var __stream = await __response.Content.ReadAsStreamAsync(
370+
#if NET5_0_OR_GREATER
371+
cancellationToken
372+
#endif
373+
).ConfigureAwait(false);
378374
using var __reader = new global::System.IO.StreamReader(__stream);
379375
380376
while (!__reader.EndOfStream && !cancellationToken.IsCancellationRequested)
@@ -445,7 +441,11 @@ public static string GenerateResponse(
445441
ContentType.String => "String",
446442
ContentType.Stream => "Stream",
447443
_ => "ByteArray",
448-
}}Async({cancellationTokenInsideReadAsync}).ConfigureAwait(false);
444+
}}Async(
445+
#if NET5_0_OR_GREATER
446+
cancellationToken
447+
#endif
448+
).ConfigureAwait(false);
449449
450450
{(endPoint.ContentType == ContentType.String ? @"
451451
ProcessResponseContent(
@@ -516,7 +516,11 @@ public static string GenerateResponse(
516516
ContentType.String => "Stream",
517517
ContentType.Stream => "Stream",
518518
_ => "ByteArray",
519-
}}Async({cancellationTokenInsideReadAsync}).ConfigureAwait(false);
519+
}}Async(
520+
#if NET5_0_OR_GREATER
521+
cancellationToken
522+
#endif
523+
).ConfigureAwait(false);
520524
521525
{(endPoint.ContentType == ContentType.String && endPoint.SuccessResponse.Type.CSharpTypeWithoutNullability is not "string" ? $@"
522526
return
@@ -662,7 +666,11 @@ SdkFeatureUsage.Always or
662666
SdkFeatureUsage.InSupportedTargetFrameworks &&
663667
!string.IsNullOrWhiteSpace(endPoint.ExperimentalStage)
664668
? $@"
665-
[global::System.Diagnostics.CodeAnalysis.Experimental(diagnosticId: ""{endPoint.Settings.Namespace.Replace(".", "_").ToUpperInvariant()}_{endPoint.ExperimentalStage.ToUpperInvariant()}_001"")]"
669+
{(endPoint.Settings.UseExperimentalAttributes is SdkFeatureUsage.InSupportedTargetFrameworks ? @"
670+
#if NET8_0_OR_GREATER" : " ")}
671+
[global::System.Diagnostics.CodeAnalysis.Experimental(diagnosticId: ""{endPoint.Settings.Namespace.Replace(".", "_").ToUpperInvariant()}_{endPoint.ExperimentalStage.ToUpperInvariant()}_001"")]
672+
{(endPoint.Settings.UseExperimentalAttributes is SdkFeatureUsage.InSupportedTargetFrameworks ? @"
673+
#endif" : " ")}"
666674
: " ")}";
667675
}
668676
}

src/libs/AutoSDK/Sources/Sources.Models.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ private static bool IsSupported(SdkFeatureUsage usage, string targetFramework)
5353
SdkFeatureUsage.Always => true,
5454
SdkFeatureUsage.InSupportedTargetFrameworks
5555
when targetFramework.StartsWith("net8", StringComparison.OrdinalIgnoreCase) => true,
56+
SdkFeatureUsage.InSupportedTargetFrameworks
57+
when targetFramework.StartsWith("net9", StringComparison.OrdinalIgnoreCase) => true,
5658
_ => false,
5759
};
5860
}
@@ -120,7 +122,13 @@ public static string GenerateClassModel(
120122
/// </summary>
121123
{properties.Where(static x => x.IsRequired || !x.IsDeprecated).Select(x => $@"
122124
{x.Summary.ToXmlDocumentationForParam(x.ParameterName, level: 8)}").Inject()}
123-
{(modelData.Settings.TargetFramework.StartsWith("net8", StringComparison.OrdinalIgnoreCase) ? "[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]" : " ")}
125+
{(modelData.Settings.UseSetsRequiredMembersAttributes is SdkFeatureUsage.Always or SdkFeatureUsage.InSupportedTargetFrameworks ? @$"
126+
{(modelData.Settings.UseExperimentalAttributes is SdkFeatureUsage.InSupportedTargetFrameworks ? @"
127+
#if NET7_0_OR_GREATER" : " ")}
128+
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
129+
{(modelData.Settings.UseExperimentalAttributes is SdkFeatureUsage.InSupportedTargetFrameworks ? @"
130+
#endif" : " ")}
131+
" : " ")}
124132
public {modelData.ClassName}(
125133
{string.Join(",",
126134
properties.Where(static x => x.IsRequired).Select(x => $@"

src/tests/AutoSDK.SnapshotTests/AutoSDK.SnapshotTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.MSTest" Version="1.1.2" />
2222
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
2323
<PackageReference Include="System.Formats.Asn1" Version="9.0.1" />
24-
<PackageReference Include="Verify.MSTest" Version="28.9.0" />
24+
<PackageReference Include="Verify.MSTest" Version="28.10.1" />
2525
<PackageReference Include="Verify.SourceGenerators" Version="2.5.0" />
2626
<PackageReference Include="H.Resources.Generator" Version="1.6.1">
2727
<PrivateAssets>all</PrivateAssets>

src/tests/AutoSDK.SnapshotTests/Snapshots/ai21/NewtonsoftJson/_#G.Api.ConvertDocumentFileStudioV1ChatFilesConvertPost.g.verified.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ partial void ProcessConvertDocumentFileStudioV1ChatFilesConvertPostResponseConte
124124

125125
if (ReadResponseAsString)
126126
{
127-
var __content = await __response.Content.ReadAsStringAsync().ConfigureAwait(false);
127+
var __content = await __response.Content.ReadAsStringAsync(
128+
#if NET5_0_OR_GREATER
129+
cancellationToken
130+
#endif
131+
).ConfigureAwait(false);
128132

129133
ProcessResponseContent(
130134
client: HttpClient,
@@ -176,7 +180,11 @@ partial void ProcessConvertDocumentFileStudioV1ChatFilesConvertPostResponseConte
176180
};
177181
}
178182

179-
var __content = await __response.Content.ReadAsStringAsync().ConfigureAwait(false);
183+
var __content = await __response.Content.ReadAsStringAsync(
184+
#if NET5_0_OR_GREATER
185+
cancellationToken
186+
#endif
187+
).ConfigureAwait(false);
180188

181189
return __content;
182190
}

src/tests/AutoSDK.SnapshotTests/Snapshots/ai21/NewtonsoftJson/_#G.Api.GenerateOrgTokenStudioV1ConnectorsConnectedUsersOrganizationIdTokensPost.g.verified.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ partial void ProcessGenerateOrgTokenStudioV1ConnectorsConnectedUsersOrganization
111111

112112
if (ReadResponseAsString)
113113
{
114-
var __content = await __response.Content.ReadAsStringAsync().ConfigureAwait(false);
114+
var __content = await __response.Content.ReadAsStringAsync(
115+
#if NET5_0_OR_GREATER
116+
cancellationToken
117+
#endif
118+
).ConfigureAwait(false);
115119

116120
ProcessResponseContent(
117121
client: HttpClient,
@@ -165,7 +169,11 @@ partial void ProcessGenerateOrgTokenStudioV1ConnectorsConnectedUsersOrganization
165169
};
166170
}
167171

168-
using var __content = await __response.Content.ReadAsStreamAsync().ConfigureAwait(false);
172+
using var __content = await __response.Content.ReadAsStreamAsync(
173+
#if NET5_0_OR_GREATER
174+
cancellationToken
175+
#endif
176+
).ConfigureAwait(false);
169177

170178
return
171179
await global::G.ConnectorsToken.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??

src/tests/AutoSDK.SnapshotTests/Snapshots/ai21/NewtonsoftJson/_#G.Api.GetDataSourceStatusStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesDataSourceStatusGet.g.verified.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@ partial void ProcessGetDataSourceStatusStudioV1ConnectorsConnectedUsersOrganizat
117117

118118
if (ReadResponseAsString)
119119
{
120-
var __content = await __response.Content.ReadAsStringAsync().ConfigureAwait(false);
120+
var __content = await __response.Content.ReadAsStringAsync(
121+
#if NET5_0_OR_GREATER
122+
cancellationToken
123+
#endif
124+
).ConfigureAwait(false);
121125

122126
ProcessResponseContent(
123127
client: HttpClient,
@@ -171,7 +175,11 @@ partial void ProcessGetDataSourceStatusStudioV1ConnectorsConnectedUsersOrganizat
171175
};
172176
}
173177

174-
using var __content = await __response.Content.ReadAsStreamAsync().ConfigureAwait(false);
178+
using var __content = await __response.Content.ReadAsStreamAsync(
179+
#if NET5_0_OR_GREATER
180+
cancellationToken
181+
#endif
182+
).ConfigureAwait(false);
175183

176184
return
177185
await global::G.ConnectorsStatus.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??

src/tests/AutoSDK.SnapshotTests/Snapshots/ai21/NewtonsoftJson/_#G.Api.GetOrgDataSourcesInfoStudioV1ConnectorsConnectedUsersOrganizationIdDataSourcesGet.g.verified.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ partial void ProcessGetOrgDataSourcesInfoStudioV1ConnectorsConnectedUsersOrganiz
111111

112112
if (ReadResponseAsString)
113113
{
114-
var __content = await __response.Content.ReadAsStringAsync().ConfigureAwait(false);
114+
var __content = await __response.Content.ReadAsStringAsync(
115+
#if NET5_0_OR_GREATER
116+
cancellationToken
117+
#endif
118+
).ConfigureAwait(false);
115119

116120
ProcessResponseContent(
117121
client: HttpClient,
@@ -165,7 +169,11 @@ partial void ProcessGetOrgDataSourcesInfoStudioV1ConnectorsConnectedUsersOrganiz
165169
};
166170
}
167171

168-
using var __content = await __response.Content.ReadAsStreamAsync().ConfigureAwait(false);
172+
using var __content = await __response.Content.ReadAsStreamAsync(
173+
#if NET5_0_OR_GREATER
174+
cancellationToken
175+
#endif
176+
).ConfigureAwait(false);
169177

170178
return
171179
await global::G.ConnectorsDataSources.FromJsonStreamAsync(__content, JsonSerializerOptions).ConfigureAwait(false) ??

0 commit comments

Comments
 (0)