From 10c2a9f04b9bce96ee72039d37ffd23e13c72754 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Fri, 25 Oct 2024 19:31:44 +0400 Subject: [PATCH] refactor: Refactored computing of AnyOf smart property names. --- .../AutoSDK/Extensions/OpenApiExtensions.cs | 13 +-- src/libs/AutoSDK/Models/AnyOfData.cs | 13 +-- src/libs/AutoSDK/Models/MethodParameter.cs | 2 +- src/libs/AutoSDK/Models/PropertyData.cs | 2 +- src/libs/AutoSDK/Models/SchemaContext.cs | 17 ++- src/libs/AutoSDK/Models/TypeData.cs | 24 ++-- .../AnyOfs}/SmartNamedAnyOfNames.cs | 15 ++- src/libs/AutoSDK/Sources/Data.cs | 6 +- ...dels.ReposGetContentResponse.g.verified.cs | 104 +++++++++--------- ...dels.ReposGetContentResponse.g.verified.cs | 104 +++++++++--------- ...ters.ReposGetContentResponse.g.verified.cs | 36 +++--- .../Tests.SmartNamedAnyOfNames.cs | 8 +- 12 files changed, 176 insertions(+), 168 deletions(-) rename src/libs/AutoSDK/{Helpers => Naming/AnyOfs}/SmartNamedAnyOfNames.cs (68%) diff --git a/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs b/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs index 22cdaa551a..190956537f 100644 --- a/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs +++ b/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs @@ -342,11 +342,10 @@ public static bool HasAllOfTypeForMetadata( public static string? GetDefaultValue(this SchemaContext context) { context = context ?? throw new ArgumentNullException(nameof(context)); - context.TypeData = context.TypeData ?? throw new InvalidOperationException("Invalid state: TypeData is null"); - if (context.TypeData.Value.CSharpType == "object?" || + if (context.TypeData.CSharpType == "object?" || context.Schema.Default is OpenApiArray || - context.TypeData.Value.CSharpTypeNullability) + context.TypeData.CSharpTypeNullability) { return string.Empty; } @@ -364,7 +363,7 @@ context.Schema.Default is OpenApiArray || return string.Empty; } - return context.TypeData.Value.CSharpTypeWithoutNullability + "." + result.Name; + return context.TypeData.CSharpTypeWithoutNullability + "." + result.Name; } if (context.Schema.AnyOf.Any(x => x.Enum.Any()) && context.Schema.Default != null) { @@ -390,7 +389,7 @@ context.Schema.Default is OpenApiArray || return null; } - return enumChildContext.TypeData?.CSharpTypeWithoutNullability + "." + value; + return enumChildContext.TypeData.CSharpTypeWithoutNullability + "." + value; } if (context.Schema.OneOf.Any(x => x.Enum.Any()) && context.Schema.Default != null) { @@ -403,7 +402,7 @@ context.Schema.Default is OpenApiArray || return string.Empty; } - return enumChildContext.TypeData?.CSharpTypeWithoutNullability + "." + result.Name; + return enumChildContext.TypeData.CSharpTypeWithoutNullability + "." + result.Name; } if (context.Schema.AllOf.Any(x => x.Enum.Any()) && context.Schema.Default != null) { @@ -416,7 +415,7 @@ context.Schema.Default is OpenApiArray || return string.Empty; } - return enumChildContext.TypeData?.CSharpTypeWithoutNullability + "." + result.Name; + return enumChildContext.TypeData.CSharpTypeWithoutNullability + "." + result.Name; } if (context.Schema.Default is OpenApiString @string && !string.IsNullOrWhiteSpace(@string.Value)) { diff --git a/src/libs/AutoSDK/Models/AnyOfData.cs b/src/libs/AutoSDK/Models/AnyOfData.cs index 4bd092549a..97e3c0356d 100644 --- a/src/libs/AutoSDK/Models/AnyOfData.cs +++ b/src/libs/AutoSDK/Models/AnyOfData.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; using AutoSDK.Extensions; -using AutoSDK.Helpers; +using AutoSDK.Naming.AnyOfs; using AutoSDK.Serialization.Json; namespace AutoSDK.Models; @@ -31,11 +31,6 @@ public static AnyOfData FromSchemaContext(SchemaContext context) : Hint.AllOf)) .ToList(); var className = context.Id.ToClassName(); - var useSmartNames = children.All(x => - x.Schema.Reference != null && - !string.IsNullOrWhiteSpace(SmartNamedAnyOfNames.ComputeSmartName( - (x.TypeData ?? TypeData.Default).ShortCSharpTypeWithoutNullability, - className))); TypeData? discriminatorType = null; string? discriminatorPropertyName = null; //IDictionary? discriminatorMapping = null; @@ -90,10 +85,10 @@ public static AnyOfData FromSchemaContext(SchemaContext context) Properties: context.IsNamedAnyOfLike ? children.Select((x, i) => PropertyData.Default with { - Type = x.TypeData ?? TypeData.Default, - Name = useSmartNames && (x.TypeData ?? TypeData.Default).CSharpTypeWithoutNullability.StartsWith("global::System.", StringComparison.Ordinal) != true + Type = x.TypeData, + Name = SmartNamedAnyOfNames.ShouldUseSmartName(children, className) ? SmartNamedAnyOfNames.ComputeSmartName( - (x.TypeData ?? TypeData.Default).ShortCSharpTypeWithoutNullability, + x.TypeData, className) : $"Value{i + 1}", Summary = x.Schema.GetSummary(), diff --git a/src/libs/AutoSDK/Models/MethodParameter.cs b/src/libs/AutoSDK/Models/MethodParameter.cs index a654331ca2..5bda46b595 100644 --- a/src/libs/AutoSDK/Models/MethodParameter.cs +++ b/src/libs/AutoSDK/Models/MethodParameter.cs @@ -48,7 +48,7 @@ public static MethodParameter FromSchemaContext(SchemaContext context) context = context ?? throw new ArgumentNullException(nameof(context)); var parameter = context.Parameter ?? throw new InvalidOperationException("Parameter or parameter data is required."); var parameterName = context.ParameterName ?? throw new InvalidOperationException("Property name or parameter name is required."); - var type = context.TypeData ?? throw new InvalidOperationException("TypeData is required."); + var type = context.TypeData; if (parameter.In == ParameterLocation.Query && (context.IsClass || context.ResolvedReference?.IsClass == true) && (context.ResolvedReference?.ClassData ?? context.ClassData)?.Properties.FirstOrDefault(x => x.Id == parameterName) is { } property && diff --git a/src/libs/AutoSDK/Models/PropertyData.cs b/src/libs/AutoSDK/Models/PropertyData.cs index 11c40241e8..6979eb8b7c 100644 --- a/src/libs/AutoSDK/Models/PropertyData.cs +++ b/src/libs/AutoSDK/Models/PropertyData.cs @@ -37,7 +37,7 @@ public static PropertyData FromSchemaContext(SchemaContext context) { context = context ?? throw new ArgumentNullException(nameof(context)); var propertyName = context.PropertyName ?? throw new InvalidOperationException("Property name or parameter name is required."); - var type = context.TypeData ?? throw new InvalidOperationException("TypeData is required."); + var type = context.TypeData; // OpenAPI doesn't allow metadata for references so sometimes allOf with single item is used to add metadata. if (context.HasAllOfTypeForMetadata()) diff --git a/src/libs/AutoSDK/Models/SchemaContext.cs b/src/libs/AutoSDK/Models/SchemaContext.cs index 0ba233e2a1..e901c447af 100644 --- a/src/libs/AutoSDK/Models/SchemaContext.cs +++ b/src/libs/AutoSDK/Models/SchemaContext.cs @@ -49,7 +49,7 @@ public class SchemaContext public OpenApiResponse? Response { get; init; } public bool IsOperation => OperationPath != null; - public TypeData? TypeData { get; set; } + public TypeData TypeData { get; set; } = TypeData.Default; public bool IsClass => Type == "class";// || ResolvedReference?.IsClass == true; //public ModelData? ClassData { get; set; } @@ -181,8 +181,6 @@ private static string ComputeType(OpenApiSchema schema, bool isComponent) return schema.Type ?? "class"; } - public string ShortType => TypeData?.CSharpType ?? Type; - public bool IsRequired => IsProperty && Parent?.Schema.Required.Contains(PropertyName) == true || Hint == Models.Hint.Parameter && Parameter?.Required == true || @@ -378,14 +376,15 @@ public void ComputeData(int level = 0, int maxDepth = 20) } TypeData = IsReference - ? ResolvedReference?.TypeData - : Models.TypeData.FromSchemaContext(this); - if (IsReference && ResolvedReference != null && TypeData.HasValue) + ? ResolvedReference?.TypeData ?? + throw new InvalidOperationException("Resolved reference must have type data.") + : TypeData.FromSchemaContext(this); + if (IsReference && ResolvedReference != null && TypeData != TypeData.Default) { - TypeData = TypeData.Value with + TypeData = TypeData with { - CSharpTypeRaw = global::AutoSDK.Models.TypeData.GetCSharpType(ResolvedReference), - CSharpTypeNullability = global::AutoSDK.Models.TypeData.GetCSharpNullability(ResolvedReference, this), + CSharpTypeRaw = TypeData.GetCSharpType(ResolvedReference), + CSharpTypeNullability = TypeData.GetCSharpNullability(ResolvedReference, this), }; } if (IsProperty) diff --git a/src/libs/AutoSDK/Models/TypeData.cs b/src/libs/AutoSDK/Models/TypeData.cs index f0faffec7f..7590fcfd35 100644 --- a/src/libs/AutoSDK/Models/TypeData.cs +++ b/src/libs/AutoSDK/Models/TypeData.cs @@ -98,29 +98,29 @@ public static TypeData FromSchemaContext(SchemaContext context) if (context.Schema.IsAnyOf()) { subTypes = context.Children - .Where(x => x is { Hint: Hint.AnyOf, TypeData: not null }) - .Select(x => x.TypeData!.Value) + .Where(x => x is { Hint: Hint.AnyOf } && x.TypeData != Default) + .Select(x => x.TypeData) .ToImmutableArray(); } else if (context.Schema.IsOneOf()) { subTypes = context.Children - .Where(x => x is { Hint: Hint.OneOf, TypeData: not null }) - .Select(x => x.TypeData!.Value) + .Where(x => x is { Hint: Hint.OneOf } && x.TypeData != Default) + .Select(x => x.TypeData) .ToImmutableArray(); } else if (context.Schema.IsAllOf()) { subTypes = context.Children - .Where(x => x is { Hint: Hint.AllOf, TypeData: not null }) - .Select(x => x.TypeData!.Value) + .Where(x => x is { Hint: Hint.AllOf } && x.TypeData != Default) + .Select(x => x.TypeData) .ToImmutableArray(); } if (context.Schema.IsArray()) { subTypes = [ context.Children - .FirstOrDefault(x => x is { Hint: Hint.ArrayItem, TypeData: not null }) + .FirstOrDefault(x => x is { Hint: Hint.ArrayItem } && x.TypeData != Default) ?.TypeData ?? Default with { @@ -218,13 +218,13 @@ public static string GetCSharpType(SchemaContext context) (_, _) when context.Schema.IsUnixTimestamp() => "global::System.DateTimeOffset", (_, _) when context.Schema.IsArray() => - $"{context.Children.FirstOrDefault(x => x.Hint == Hint.ArrayItem)?.TypeData?.CSharpTypeWithoutNullability}".AsArray(), + $"{context.Children.FirstOrDefault(x => x.Hint == Hint.ArrayItem)?.TypeData.CSharpTypeWithoutNullability}".AsArray(), (_, _) when context.IsNamedAnyOfLike => $"global::{context.Settings.Namespace}.{context.Id}", - (_, _) when context.Schema.IsAnyOf() => $"global::{context.Settings.Namespace}.AnyOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.AnyOf).Select(x => x.TypeData?.CSharpTypeWithNullabilityForValueTypes))}>", - (_, _) when context.Schema.IsOneOf() => $"global::{context.Settings.Namespace}.OneOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.OneOf).Select(x => x.TypeData?.CSharpTypeWithNullabilityForValueTypes))}>", - (_, _) when context.Schema.IsAllOf() => $"global::{context.Settings.Namespace}.AllOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.AllOf).Select(x => x.TypeData?.CSharpTypeWithNullabilityForValueTypes))}>", + (_, _) when context.Schema.IsAnyOf() => $"global::{context.Settings.Namespace}.AnyOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.AnyOf).Select(x => x.TypeData.CSharpTypeWithNullabilityForValueTypes))}>", + (_, _) when context.Schema.IsOneOf() => $"global::{context.Settings.Namespace}.OneOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.OneOf).Select(x => x.TypeData.CSharpTypeWithNullabilityForValueTypes))}>", + (_, _) when context.Schema.IsAllOf() => $"global::{context.Settings.Namespace}.AllOf<{string.Join(", ", context.Children.Where(x => x.Hint == Hint.AllOf).Select(x => x.TypeData.CSharpTypeWithNullabilityForValueTypes))}>", ("object", _) or (null, _) when context.Schema.Reference != null && @@ -243,7 +243,7 @@ public static string GetCSharpType(SchemaContext context) ("object", _) when context.Schema.AdditionalProperties?.Type is not null => - $"global::System.Collections.Generic.Dictionary x.Hint == Hint.AdditionalProperties)?.TypeData?.CSharpType}>", + $"global::System.Collections.Generic.Dictionary x.Hint == Hint.AdditionalProperties)?.TypeData.CSharpType}>", ("string", _) when context.Schema.Enum.Any() => $"global::{context.Settings.Namespace}.{context.Id}", diff --git a/src/libs/AutoSDK/Helpers/SmartNamedAnyOfNames.cs b/src/libs/AutoSDK/Naming/AnyOfs/SmartNamedAnyOfNames.cs similarity index 68% rename from src/libs/AutoSDK/Helpers/SmartNamedAnyOfNames.cs rename to src/libs/AutoSDK/Naming/AnyOfs/SmartNamedAnyOfNames.cs index 08f43acb47..218b96d2e5 100644 --- a/src/libs/AutoSDK/Helpers/SmartNamedAnyOfNames.cs +++ b/src/libs/AutoSDK/Naming/AnyOfs/SmartNamedAnyOfNames.cs @@ -1,9 +1,20 @@ -namespace AutoSDK.Helpers; +using AutoSDK.Models; + +namespace AutoSDK.Naming.AnyOfs; public static class SmartNamedAnyOfNames { - public static string ComputeSmartName(string typeName, string className) + public static bool ShouldUseSmartName(IList children, string className) + { + return children.All(x => + x.Schema.Reference != null && + !string.IsNullOrWhiteSpace(ComputeSmartName(x.TypeData, className)) && + x.TypeData.CSharpTypeWithoutNullability.StartsWith("global::System.", StringComparison.Ordinal) != true); + } + + public static string ComputeSmartName(TypeData typeData, string className) { + var typeName = typeData.ShortCSharpTypeWithoutNullability; var nameWords = SplitToWordsByUpperCharacters(typeName); var classNameWords = SplitToWordsByUpperCharacters(className); diff --git a/src/libs/AutoSDK/Sources/Data.cs b/src/libs/AutoSDK/Sources/Data.cs index 54e7da0299..50637b1000 100644 --- a/src/libs/AutoSDK/Sources/Data.cs +++ b/src/libs/AutoSDK/Sources/Data.cs @@ -265,9 +265,9 @@ .. includedTags.Select(tag => PropertyData.Default with settings.GenerateJsonSerializerContextTypes ? filteredSchemas .Where(x => - x is { TypeData: not null } && - !string.IsNullOrWhiteSpace(x.TypeData!.Value.CSharpType)) - .Select(x => x.TypeData!.Value) + x.TypeData != TypeData.Default && + !string.IsNullOrWhiteSpace(x.TypeData.CSharpType)) + .Select(x => x.TypeData) .GroupBy(x => x.CSharpTypeWithNullability) .Select(x => x.First()) .ToImmutableArray() diff --git a/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.Models.ReposGetContentResponse.g.verified.cs b/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.Models.ReposGetContentResponse.g.verified.cs index 9356756231..aa84a8bb41 100644 --- a/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.Models.ReposGetContentResponse.g.verified.cs +++ b/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/NewtonsoftJson/_#G.Models.ReposGetContentResponse.g.verified.cs @@ -40,18 +40,18 @@ public ReposGetContentResponse(global::System.Collections.Generic.IList #if NET6_0_OR_GREATER - public global::G.ContentFile? File { get; init; } + public global::G.ContentFile? Value2 { get; init; } #else - public global::G.ContentFile? File { get; } + public global::G.ContentFile? Value2 { get; } #endif /// /// /// #if NET6_0_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(File))] + [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Value2))] #endif - public bool IsFile => File != null; + public bool IsValue2 => Value2 != null; /// /// @@ -61,32 +61,32 @@ public ReposGetContentResponse(global::System.Collections.Generic.IList /// /// - public static implicit operator global::G.ContentFile?(ReposGetContentResponse @this) => @this.File; + public static implicit operator global::G.ContentFile?(ReposGetContentResponse @this) => @this.Value2; /// /// /// public ReposGetContentResponse(global::G.ContentFile? value) { - File = value; + Value2 = value; } /// /// An object describing a symlink /// #if NET6_0_OR_GREATER - public global::G.ContentSymlink? Symlink { get; init; } + public global::G.ContentSymlink? Value3 { get; init; } #else - public global::G.ContentSymlink? Symlink { get; } + public global::G.ContentSymlink? Value3 { get; } #endif /// /// /// #if NET6_0_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Symlink))] + [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Value3))] #endif - public bool IsSymlink => Symlink != null; + public bool IsValue3 => Value3 != null; /// /// @@ -96,32 +96,32 @@ public ReposGetContentResponse(global::G.ContentFile? value) /// /// /// - public static implicit operator global::G.ContentSymlink?(ReposGetContentResponse @this) => @this.Symlink; + public static implicit operator global::G.ContentSymlink?(ReposGetContentResponse @this) => @this.Value3; /// /// /// public ReposGetContentResponse(global::G.ContentSymlink? value) { - Symlink = value; + Value3 = value; } /// /// An object describing a submodule /// #if NET6_0_OR_GREATER - public global::G.ContentSubmodule? Submodule { get; init; } + public global::G.ContentSubmodule? Value4 { get; init; } #else - public global::G.ContentSubmodule? Submodule { get; } + public global::G.ContentSubmodule? Value4 { get; } #endif /// /// /// #if NET6_0_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Submodule))] + [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Value4))] #endif - public bool IsSubmodule => Submodule != null; + public bool IsValue4 => Value4 != null; /// /// @@ -131,14 +131,14 @@ public ReposGetContentResponse(global::G.ContentSymlink? value) /// /// /// - public static implicit operator global::G.ContentSubmodule?(ReposGetContentResponse @this) => @this.Submodule; + public static implicit operator global::G.ContentSubmodule?(ReposGetContentResponse @this) => @this.Value4; /// /// /// public ReposGetContentResponse(global::G.ContentSubmodule? value) { - Submodule = value; + Value4 = value; } /// @@ -146,24 +146,24 @@ public ReposGetContentResponse(global::G.ContentSubmodule? value) /// public ReposGetContentResponse( global::System.Collections.Generic.IList? value1, - global::G.ContentFile? file, - global::G.ContentSymlink? symlink, - global::G.ContentSubmodule? submodule + global::G.ContentFile? value2, + global::G.ContentSymlink? value3, + global::G.ContentSubmodule? value4 ) { Value1 = value1; - File = file; - Symlink = symlink; - Submodule = submodule; + Value2 = value2; + Value3 = value3; + Value4 = value4; } /// /// /// public object? Object => - Submodule as object ?? - Symlink as object ?? - File as object ?? + Value4 as object ?? + Value3 as object ?? + Value2 as object ?? Value1 as object ; @@ -172,7 +172,7 @@ Value1 as object /// public bool Validate() { - return IsValue1 && !IsFile && !IsSymlink && !IsSubmodule || !IsValue1 && IsFile && !IsSymlink && !IsSubmodule || !IsValue1 && !IsFile && IsSymlink && !IsSubmodule || !IsValue1 && !IsFile && !IsSymlink && IsSubmodule; + return IsValue1 && !IsValue2 && !IsValue3 && !IsValue4 || !IsValue1 && IsValue2 && !IsValue3 && !IsValue4 || !IsValue1 && !IsValue2 && IsValue3 && !IsValue4 || !IsValue1 && !IsValue2 && !IsValue3 && IsValue4; } /// @@ -180,9 +180,9 @@ public bool Validate() /// public TResult? Match( global::System.Func?, TResult>? value1 = null, - global::System.Func? file = null, - global::System.Func? symlink = null, - global::System.Func? submodule = null, + global::System.Func? value2 = null, + global::System.Func? value3 = null, + global::System.Func? value4 = null, bool validate = true) { if (validate) @@ -194,17 +194,17 @@ public bool Validate() { return value1(Value1!); } - else if (IsFile && file != null) + else if (IsValue2 && value2 != null) { - return file(File!); + return value2(Value2!); } - else if (IsSymlink && symlink != null) + else if (IsValue3 && value3 != null) { - return symlink(Symlink!); + return value3(Value3!); } - else if (IsSubmodule && submodule != null) + else if (IsValue4 && value4 != null) { - return submodule(Submodule!); + return value4(Value4!); } return default(TResult); @@ -215,9 +215,9 @@ public bool Validate() /// public void Match( global::System.Action?>? value1 = null, - global::System.Action? file = null, - global::System.Action? symlink = null, - global::System.Action? submodule = null, + global::System.Action? value2 = null, + global::System.Action? value3 = null, + global::System.Action? value4 = null, bool validate = true) { if (validate) @@ -229,17 +229,17 @@ public void Match( { value1?.Invoke(Value1!); } - else if (IsFile) + else if (IsValue2) { - file?.Invoke(File!); + value2?.Invoke(Value2!); } - else if (IsSymlink) + else if (IsValue3) { - symlink?.Invoke(Symlink!); + value3?.Invoke(Value3!); } - else if (IsSubmodule) + else if (IsValue4) { - submodule?.Invoke(Submodule!); + value4?.Invoke(Value4!); } } @@ -252,11 +252,11 @@ public override int GetHashCode() { Value1, typeof(global::System.Collections.Generic.IList), - File, + Value2, typeof(global::G.ContentFile), - Symlink, + Value3, typeof(global::G.ContentSymlink), - Submodule, + Value4, typeof(global::G.ContentSubmodule), }; const int offset = unchecked((int)2166136261); @@ -274,9 +274,9 @@ public bool Equals(ReposGetContentResponse other) { return global::System.Collections.Generic.EqualityComparer?>.Default.Equals(Value1, other.Value1) && - global::System.Collections.Generic.EqualityComparer.Default.Equals(File, other.File) && - global::System.Collections.Generic.EqualityComparer.Default.Equals(Symlink, other.Symlink) && - global::System.Collections.Generic.EqualityComparer.Default.Equals(Submodule, other.Submodule) + global::System.Collections.Generic.EqualityComparer.Default.Equals(Value2, other.Value2) && + global::System.Collections.Generic.EqualityComparer.Default.Equals(Value3, other.Value3) && + global::System.Collections.Generic.EqualityComparer.Default.Equals(Value4, other.Value4) ; } diff --git a/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.Models.ReposGetContentResponse.g.verified.cs b/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.Models.ReposGetContentResponse.g.verified.cs index ef382149db..cc8ae921a9 100644 --- a/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.Models.ReposGetContentResponse.g.verified.cs +++ b/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#G.Models.ReposGetContentResponse.g.verified.cs @@ -40,18 +40,18 @@ public ReposGetContentResponse(global::System.Collections.Generic.IList #if NET6_0_OR_GREATER - public global::G.ContentFile? File { get; init; } + public global::G.ContentFile? Value2 { get; init; } #else - public global::G.ContentFile? File { get; } + public global::G.ContentFile? Value2 { get; } #endif /// /// /// #if NET6_0_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(File))] + [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Value2))] #endif - public bool IsFile => File != null; + public bool IsValue2 => Value2 != null; /// /// @@ -61,32 +61,32 @@ public ReposGetContentResponse(global::System.Collections.Generic.IList /// /// - public static implicit operator global::G.ContentFile?(ReposGetContentResponse @this) => @this.File; + public static implicit operator global::G.ContentFile?(ReposGetContentResponse @this) => @this.Value2; /// /// /// public ReposGetContentResponse(global::G.ContentFile? value) { - File = value; + Value2 = value; } /// /// An object describing a symlink /// #if NET6_0_OR_GREATER - public global::G.ContentSymlink? Symlink { get; init; } + public global::G.ContentSymlink? Value3 { get; init; } #else - public global::G.ContentSymlink? Symlink { get; } + public global::G.ContentSymlink? Value3 { get; } #endif /// /// /// #if NET6_0_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Symlink))] + [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Value3))] #endif - public bool IsSymlink => Symlink != null; + public bool IsValue3 => Value3 != null; /// /// @@ -96,32 +96,32 @@ public ReposGetContentResponse(global::G.ContentFile? value) /// /// /// - public static implicit operator global::G.ContentSymlink?(ReposGetContentResponse @this) => @this.Symlink; + public static implicit operator global::G.ContentSymlink?(ReposGetContentResponse @this) => @this.Value3; /// /// /// public ReposGetContentResponse(global::G.ContentSymlink? value) { - Symlink = value; + Value3 = value; } /// /// An object describing a submodule /// #if NET6_0_OR_GREATER - public global::G.ContentSubmodule? Submodule { get; init; } + public global::G.ContentSubmodule? Value4 { get; init; } #else - public global::G.ContentSubmodule? Submodule { get; } + public global::G.ContentSubmodule? Value4 { get; } #endif /// /// /// #if NET6_0_OR_GREATER - [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Submodule))] + [global::System.Diagnostics.CodeAnalysis.MemberNotNullWhen(true, nameof(Value4))] #endif - public bool IsSubmodule => Submodule != null; + public bool IsValue4 => Value4 != null; /// /// @@ -131,14 +131,14 @@ public ReposGetContentResponse(global::G.ContentSymlink? value) /// /// /// - public static implicit operator global::G.ContentSubmodule?(ReposGetContentResponse @this) => @this.Submodule; + public static implicit operator global::G.ContentSubmodule?(ReposGetContentResponse @this) => @this.Value4; /// /// /// public ReposGetContentResponse(global::G.ContentSubmodule? value) { - Submodule = value; + Value4 = value; } /// @@ -146,24 +146,24 @@ public ReposGetContentResponse(global::G.ContentSubmodule? value) /// public ReposGetContentResponse( global::System.Collections.Generic.IList? value1, - global::G.ContentFile? file, - global::G.ContentSymlink? symlink, - global::G.ContentSubmodule? submodule + global::G.ContentFile? value2, + global::G.ContentSymlink? value3, + global::G.ContentSubmodule? value4 ) { Value1 = value1; - File = file; - Symlink = symlink; - Submodule = submodule; + Value2 = value2; + Value3 = value3; + Value4 = value4; } /// /// /// public object? Object => - Submodule as object ?? - Symlink as object ?? - File as object ?? + Value4 as object ?? + Value3 as object ?? + Value2 as object ?? Value1 as object ; @@ -172,7 +172,7 @@ Value1 as object /// public bool Validate() { - return IsValue1 && !IsFile && !IsSymlink && !IsSubmodule || !IsValue1 && IsFile && !IsSymlink && !IsSubmodule || !IsValue1 && !IsFile && IsSymlink && !IsSubmodule || !IsValue1 && !IsFile && !IsSymlink && IsSubmodule; + return IsValue1 && !IsValue2 && !IsValue3 && !IsValue4 || !IsValue1 && IsValue2 && !IsValue3 && !IsValue4 || !IsValue1 && !IsValue2 && IsValue3 && !IsValue4 || !IsValue1 && !IsValue2 && !IsValue3 && IsValue4; } /// @@ -180,9 +180,9 @@ public bool Validate() /// public TResult? Match( global::System.Func?, TResult>? value1 = null, - global::System.Func? file = null, - global::System.Func? symlink = null, - global::System.Func? submodule = null, + global::System.Func? value2 = null, + global::System.Func? value3 = null, + global::System.Func? value4 = null, bool validate = true) { if (validate) @@ -194,17 +194,17 @@ public bool Validate() { return value1(Value1!); } - else if (IsFile && file != null) + else if (IsValue2 && value2 != null) { - return file(File!); + return value2(Value2!); } - else if (IsSymlink && symlink != null) + else if (IsValue3 && value3 != null) { - return symlink(Symlink!); + return value3(Value3!); } - else if (IsSubmodule && submodule != null) + else if (IsValue4 && value4 != null) { - return submodule(Submodule!); + return value4(Value4!); } return default(TResult); @@ -215,9 +215,9 @@ public bool Validate() /// public void Match( global::System.Action?>? value1 = null, - global::System.Action? file = null, - global::System.Action? symlink = null, - global::System.Action? submodule = null, + global::System.Action? value2 = null, + global::System.Action? value3 = null, + global::System.Action? value4 = null, bool validate = true) { if (validate) @@ -229,17 +229,17 @@ public void Match( { value1?.Invoke(Value1!); } - else if (IsFile) + else if (IsValue2) { - file?.Invoke(File!); + value2?.Invoke(Value2!); } - else if (IsSymlink) + else if (IsValue3) { - symlink?.Invoke(Symlink!); + value3?.Invoke(Value3!); } - else if (IsSubmodule) + else if (IsValue4) { - submodule?.Invoke(Submodule!); + value4?.Invoke(Value4!); } } @@ -252,11 +252,11 @@ public override int GetHashCode() { Value1, typeof(global::System.Collections.Generic.IList), - File, + Value2, typeof(global::G.ContentFile), - Symlink, + Value3, typeof(global::G.ContentSymlink), - Submodule, + Value4, typeof(global::G.ContentSubmodule), }; const int offset = unchecked((int)2166136261); @@ -274,9 +274,9 @@ public bool Equals(ReposGetContentResponse other) { return global::System.Collections.Generic.EqualityComparer?>.Default.Equals(Value1, other.Value1) && - global::System.Collections.Generic.EqualityComparer.Default.Equals(File, other.File) && - global::System.Collections.Generic.EqualityComparer.Default.Equals(Symlink, other.Symlink) && - global::System.Collections.Generic.EqualityComparer.Default.Equals(Submodule, other.Submodule) + global::System.Collections.Generic.EqualityComparer.Default.Equals(Value2, other.Value2) && + global::System.Collections.Generic.EqualityComparer.Default.Equals(Value3, other.Value3) && + global::System.Collections.Generic.EqualityComparer.Default.Equals(Value4, other.Value4) ; } diff --git a/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#JsonConverters.ReposGetContentResponse.g.verified.cs b/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#JsonConverters.ReposGetContentResponse.g.verified.cs index e5784f68f5..9f31a0645e 100644 --- a/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#JsonConverters.ReposGetContentResponse.g.verified.cs +++ b/src/tests/AutoSDK.SnapshotTests/Snapshots/GitHub/SystemTextJson/_#JsonConverters.ReposGetContentResponse.g.verified.cs @@ -30,36 +30,36 @@ public class ReposGetContentResponseJsonConverter : global::System.Text.Json.Ser } readerCopy = reader; - global::G.ContentFile? file = default; + global::G.ContentFile? value2 = default; try { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ContentFile), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::G.ContentFile).Name}"); - file = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, typeInfo); + value2 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, typeInfo); } catch (global::System.Text.Json.JsonException) { } readerCopy = reader; - global::G.ContentSymlink? symlink = default; + global::G.ContentSymlink? value3 = default; try { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ContentSymlink), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::G.ContentSymlink).Name}"); - symlink = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, typeInfo); + value3 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, typeInfo); } catch (global::System.Text.Json.JsonException) { } readerCopy = reader; - global::G.ContentSubmodule? submodule = default; + global::G.ContentSubmodule? value4 = default; try { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ContentSubmodule), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::G.ContentSubmodule).Name}"); - submodule = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, typeInfo); + value4 = global::System.Text.Json.JsonSerializer.Deserialize(ref readerCopy, typeInfo); } catch (global::System.Text.Json.JsonException) { @@ -67,9 +67,9 @@ public class ReposGetContentResponseJsonConverter : global::System.Text.Json.Ser var result = new global::G.ReposGetContentResponse( value1, - file, - symlink, - submodule + value2, + value3, + value4 ); if (value1 != null) @@ -78,19 +78,19 @@ public class ReposGetContentResponseJsonConverter : global::System.Text.Json.Ser throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::System.Collections.Generic.IList).Name}"); _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo); } - else if (file != null) + else if (value2 != null) { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ContentFile), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::G.ContentFile).Name}"); _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo); } - else if (symlink != null) + else if (value3 != null) { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ContentSymlink), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::G.ContentSymlink).Name}"); _ = global::System.Text.Json.JsonSerializer.Deserialize(ref reader, typeInfo); } - else if (submodule != null) + else if (value4 != null) { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ContentSubmodule), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::G.ContentSubmodule).Name}"); @@ -115,23 +115,23 @@ public override void Write( throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::System.Collections.Generic.IList).Name}"); global::System.Text.Json.JsonSerializer.Serialize(writer, value.Value1, typeInfo); } - else if (value.IsFile) + else if (value.IsValue2) { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ContentFile), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::G.ContentFile).Name}"); - global::System.Text.Json.JsonSerializer.Serialize(writer, value.File, typeInfo); + global::System.Text.Json.JsonSerializer.Serialize(writer, value.Value2, typeInfo); } - else if (value.IsSymlink) + else if (value.IsValue3) { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ContentSymlink), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::G.ContentSymlink).Name}"); - global::System.Text.Json.JsonSerializer.Serialize(writer, value.Symlink, typeInfo); + global::System.Text.Json.JsonSerializer.Serialize(writer, value.Value3, typeInfo); } - else if (value.IsSubmodule) + else if (value.IsValue4) { var typeInfo = typeInfoResolver.GetTypeInfo(typeof(global::G.ContentSubmodule), options) as global::System.Text.Json.Serialization.Metadata.JsonTypeInfo ?? throw new global::System.InvalidOperationException($"Cannot get type info for {typeof(global::G.ContentSubmodule).Name}"); - global::System.Text.Json.JsonSerializer.Serialize(writer, value.Submodule, typeInfo); + global::System.Text.Json.JsonSerializer.Serialize(writer, value.Value4, typeInfo); } } } diff --git a/src/tests/AutoSDK.UnitTests/Tests.SmartNamedAnyOfNames.cs b/src/tests/AutoSDK.UnitTests/Tests.SmartNamedAnyOfNames.cs index 0f577e5b9a..b569f4da73 100644 --- a/src/tests/AutoSDK.UnitTests/Tests.SmartNamedAnyOfNames.cs +++ b/src/tests/AutoSDK.UnitTests/Tests.SmartNamedAnyOfNames.cs @@ -1,4 +1,5 @@ -using AutoSDK.Helpers; +using AutoSDK.Models; +using AutoSDK.Naming.AnyOfs; namespace AutoSDK.UnitTests; @@ -9,7 +10,10 @@ public partial class Tests public void SmartNamedAnyOfNames_Valid() { SmartNamedAnyOfNames.ComputeSmartName( - typeName: "ChatCompletionRequestMessageContentPartText", + typeData: TypeData.Default with + { + CSharpTypeRaw = "ChatCompletionRequestMessageContentPartText", + }, className: "ChatCompletionRequestMessageContentPart").Should().Be("Text"); }