Skip to content

Commit f9f9cff

Browse files
committed
fix: Fixed deprecation warning for AnyOf/OneOf/AllOf types.
1 parent a1a6b0a commit f9f9cff

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

src/libs/AutoSDK/Models/MethodParameter.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Immutable;
22
using Microsoft.OpenApi.Models;
33
using AutoSDK.Extensions;
4+
using AutoSDK.Helpers;
45
using AutoSDK.Naming.Properties;
56
using AutoSDK.Serialization.Json;
67

@@ -205,4 +206,13 @@ public string ArgumentName
205206
DefaultValue == null || string.IsNullOrWhiteSpace(DefaultValue) || Type.IsAnyOfLike
206207
? "default"
207208
: DefaultValue;
209+
210+
public bool ProducesDeprecationWarning =>
211+
Type.IsAnyOfLike &&
212+
Type.SubTypes.Any(static x => x.Unbox<TypeData>().IsDeprecated);
213+
214+
public string DisableDeprecationWarningIfRequired =>
215+
ProducesDeprecationWarning
216+
? "#pragma warning disable CS0618 // Type or member is obsolete"
217+
: " ";
208218
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,13 @@ public static string GenerateExtensionMethod(
641641
{GenerateEndPointAttributes(endPoint)}
642642
{(isInterface ? "" : "public async ")}{taskType} {endPoint.MethodName}(
643643
{parameters.Where(static x => x.IsRequired).Select(x => $@"
644-
{x.Type.CSharpType} {x.ParameterName},").Inject()}
644+
{x.DisableDeprecationWarningIfRequired}
645+
{x.Type.CSharpType} {x.ParameterName},
646+
{x.DisableDeprecationWarningIfRequired}".TrimEnd()).Inject()}
645647
{parameters.Where(static x => x is { IsRequired: false }).Select(x => $@"
646-
{x.Type.CSharpType} {x.ParameterName} = {x.ParameterDefaultValue},").Inject()}
648+
{x.DisableDeprecationWarningIfRequired}
649+
{x.Type.CSharpType} {x.ParameterName} = {x.ParameterDefaultValue},
650+
{x.DisableDeprecationWarningIfRequired}".TrimEnd()).Inject()}
647651
{cancellationTokenAttribute}global::System.Threading.CancellationToken cancellationToken = default){body}
648652
".RemoveBlankLinesWhereOnlyWhitespaces();
649653
}

src/tests/AutoSDK.SnapshotTests/Snapshots/openai/NewtonsoftJson/_#G.EvalsClient.CreateEval.g.verified.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ partial void ProcessCreateEvalResponseContent(
192192
/// <param name="cancellationToken">The token to cancel the operation with</param>
193193
/// <exception cref="global::System.InvalidOperationException"></exception>
194194
public async global::System.Threading.Tasks.Task<global::G.Eval> CreateEvalAsync(
195+
#pragma warning disable CS0618 // Type or member is obsolete
195196
global::G.OneOf<global::G.CreateEvalCustomDataSourceConfig, global::G.CreateEvalLogsDataSourceConfig, global::G.CreateEvalStoredCompletionsDataSourceConfig> dataSourceConfig,
197+
#pragma warning disable CS0618 // Type or member is obsolete
196198
global::System.Collections.Generic.IList<global::G.OneOf<global::G.CreateEvalLabelModelGrader, global::G.EvalGraderStringCheck?, global::G.EvalGraderTextSimilarity?, global::G.EvalGraderPython?, global::G.EvalGraderScoreModel?>> testingCriteria,
197199
string? name = default,
198200
global::System.Collections.Generic.Dictionary<string, string>? metadata = default,

src/tests/AutoSDK.SnapshotTests/Snapshots/openai/NewtonsoftJson/_#G.IEvalsClient.CreateEval.g.verified.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public partial interface IEvalsClient
4141
/// <param name="cancellationToken">The token to cancel the operation with</param>
4242
/// <exception cref="global::System.InvalidOperationException"></exception>
4343
global::System.Threading.Tasks.Task<global::G.Eval> CreateEvalAsync(
44+
#pragma warning disable CS0618 // Type or member is obsolete
4445
global::G.OneOf<global::G.CreateEvalCustomDataSourceConfig, global::G.CreateEvalLogsDataSourceConfig, global::G.CreateEvalStoredCompletionsDataSourceConfig> dataSourceConfig,
46+
#pragma warning disable CS0618 // Type or member is obsolete
4547
global::System.Collections.Generic.IList<global::G.OneOf<global::G.CreateEvalLabelModelGrader, global::G.EvalGraderStringCheck?, global::G.EvalGraderTextSimilarity?, global::G.EvalGraderPython?, global::G.EvalGraderScoreModel?>> testingCriteria,
4648
string? name = default,
4749
global::System.Collections.Generic.Dictionary<string, string>? metadata = default,

src/tests/AutoSDK.SnapshotTests/Snapshots/openai/SystemTextJson/_#G.EvalsClient.CreateEval.g.verified.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ partial void ProcessCreateEvalResponseContent(
192192
/// <param name="cancellationToken">The token to cancel the operation with</param>
193193
/// <exception cref="global::System.InvalidOperationException"></exception>
194194
public async global::System.Threading.Tasks.Task<global::G.Eval> CreateEvalAsync(
195+
#pragma warning disable CS0618 // Type or member is obsolete
195196
global::G.OneOf<global::G.CreateEvalCustomDataSourceConfig, global::G.CreateEvalLogsDataSourceConfig, global::G.CreateEvalStoredCompletionsDataSourceConfig> dataSourceConfig,
197+
#pragma warning disable CS0618 // Type or member is obsolete
196198
global::System.Collections.Generic.IList<global::G.OneOf<global::G.CreateEvalLabelModelGrader, global::G.EvalGraderStringCheck?, global::G.EvalGraderTextSimilarity?, global::G.EvalGraderPython?, global::G.EvalGraderScoreModel?>> testingCriteria,
197199
string? name = default,
198200
global::System.Collections.Generic.Dictionary<string, string>? metadata = default,

src/tests/AutoSDK.SnapshotTests/Snapshots/openai/SystemTextJson/_#G.IEvalsClient.CreateEval.g.verified.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public partial interface IEvalsClient
4141
/// <param name="cancellationToken">The token to cancel the operation with</param>
4242
/// <exception cref="global::System.InvalidOperationException"></exception>
4343
global::System.Threading.Tasks.Task<global::G.Eval> CreateEvalAsync(
44+
#pragma warning disable CS0618 // Type or member is obsolete
4445
global::G.OneOf<global::G.CreateEvalCustomDataSourceConfig, global::G.CreateEvalLogsDataSourceConfig, global::G.CreateEvalStoredCompletionsDataSourceConfig> dataSourceConfig,
46+
#pragma warning disable CS0618 // Type or member is obsolete
4547
global::System.Collections.Generic.IList<global::G.OneOf<global::G.CreateEvalLabelModelGrader, global::G.EvalGraderStringCheck?, global::G.EvalGraderTextSimilarity?, global::G.EvalGraderPython?, global::G.EvalGraderScoreModel?>> testingCriteria,
4648
string? name = default,
4749
global::System.Collections.Generic.Dictionary<string, string>? metadata = default,

0 commit comments

Comments
 (0)