diff --git a/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs b/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs index 190956537f..cdccc04273 100644 --- a/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs +++ b/src/libs/AutoSDK/Extensions/OpenApiExtensions.cs @@ -636,6 +636,7 @@ public static Dictionary ComputeEnum( description: description, settings)) .Where(value => !string.IsNullOrWhiteSpace(value.Name)) + .Distinct() .ToDictionary(x => x.Id, x => x); if (values.All(x => x.Value.Name.ToUpperInvariant().Contains(enumName.ToUpperInvariant()))) diff --git a/src/libs/AutoSDK/Helpers/EquatableArray{T}.cs b/src/libs/AutoSDK/Helpers/EquatableArray{T}.cs index ab551a44d8..29f87e1b21 100644 --- a/src/libs/AutoSDK/Helpers/EquatableArray{T}.cs +++ b/src/libs/AutoSDK/Helpers/EquatableArray{T}.cs @@ -67,6 +67,15 @@ public bool IsEmpty get => AsImmutableArray().IsEmpty; } + /// + /// Gets a length of the current array. + /// + public int Length + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => AsImmutableArray().Length; + } + /// public bool Equals(EquatableArray other) { @@ -104,6 +113,11 @@ public override int GetHashCode() [MethodImpl(MethodImplOptions.AggressiveInlining)] public ImmutableArray AsImmutableArray() { + if (_array is null) + { + return ImmutableArray.Empty; + } + return Unsafe.As>(ref Unsafe.AsRef(in _array)); } diff --git a/src/libs/AutoSDK/Models/TypeData.cs b/src/libs/AutoSDK/Models/TypeData.cs index 7590fcfd35..d4d060146d 100644 --- a/src/libs/AutoSDK/Models/TypeData.cs +++ b/src/libs/AutoSDK/Models/TypeData.cs @@ -20,9 +20,9 @@ public readonly record struct TypeData( int AllOfCount, bool IsComponent, bool HasDiscriminator, - ImmutableArray Properties, - ImmutableArray EnumValues, - ImmutableArray SubTypes, + EquatableArray Properties, + EquatableArray EnumValues, + EquatableArray SubTypes, string Namespace, bool IsDeprecated, Settings Settings) diff --git a/src/tests/AutoSDK.UnitTests/JsonTests.JsonSerializerContextTypes.cs b/src/tests/AutoSDK.UnitTests/JsonTests.JsonSerializerContextTypes.cs index 1a4dc6a21b..8b7f0ab052 100644 --- a/src/tests/AutoSDK.UnitTests/JsonTests.JsonSerializerContextTypes.cs +++ b/src/tests/AutoSDK.UnitTests/JsonTests.JsonSerializerContextTypes.cs @@ -1,4 +1,5 @@ -using AutoSDK.Models; +using System.Collections.Immutable; +using AutoSDK.Models; using static AutoSDK.Serialization.Json.SystemTextJsonSerializer; namespace AutoSDK.UnitTests; @@ -13,19 +14,19 @@ public void ContextTypes() Namespace = "System.Collections.Generic", CSharpTypeRaw = "global::System.Collections.Generic.IList", IsArray = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "string" } - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("IListString"); GetContextType(TypeData.Default with { Namespace = "System.Collections.Generic", CSharpTypeRaw = "global::System.Collections.Generic.Dictionary", - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "string" }, TypeData.Default with { CSharpTypeRaw = "int" } - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("DictionaryStringInt32"); GetContextType(TypeData.Default with @@ -33,16 +34,16 @@ public void ContextTypes() Namespace = "System.Collections.Generic", CSharpTypeRaw = "global::System.Collections.Generic.IList>", IsArray = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "global::System.Collections.Generic.IList", IsArray = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "string" } - ], + ]), } - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("IListIListString"); GetContextType(TypeData.Default with @@ -50,52 +51,52 @@ TypeData.Default with Namespace = "System.Collections.Generic", CSharpTypeRaw = "global::System.Collections.Generic.IList", IsArray = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { Namespace = "System", CSharpTypeRaw = "global::System.Guid" } - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("IListGuid"); GetContextType(TypeData.Default with { CSharpTypeRaw = "byte[]", IsBinary = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "byte" } - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("ByteArray"); GetContextType(TypeData.Default with { CSharpTypeRaw = "byte[][]", IsBinary = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "byte[]", IsBinary = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "byte" } - ], + ]), } - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("ByteArrayArray"); GetContextType(TypeData.Default with { CSharpTypeRaw = "global::System.Collections.Generic.IList", IsArray = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "byte[]", IsBinary = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "byte" } - ], + ]), } - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("IListByteArray"); GetContextType(TypeData.Default with @@ -103,7 +104,7 @@ TypeData.Default with Namespace = "G", IsValueType = true, CSharpTypeRaw = "global::G.AllOf", - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "Integration", @@ -113,7 +114,7 @@ TypeData.Default with { CSharpTypeRaw = "AppsCreateFromManifestResponse" }, - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("NullableAllOfIntegrationAppsCreateFromManifestResponse"); GetContextType(TypeData.Default with @@ -121,7 +122,7 @@ TypeData.Default with Namespace = "Cohere", IsValueType = true, CSharpTypeRaw = "global::Cohere.OneOf", - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { Namespace = "Cohere", @@ -134,7 +135,7 @@ TypeData.Default with CSharpTypeNullability = true, IsValueType = true, } - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("NullableOneOfNonStreamedChatResponseNullableStreamedChatResponse"); GetContextType(TypeData.Default with @@ -147,23 +148,23 @@ TypeData.Default with { CSharpTypeRaw = "global::System.Collections.Generic.IList", IsArray = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "byte[][]", IsBinary = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "byte[]", IsBinary = true, - SubTypes = [ + SubTypes = ImmutableArray.Create([ TypeData.Default with { CSharpTypeRaw = "byte" } - ], + ]), } - ], + ]), } - ], + ]), }, makeNullableRootIfValueType: true).Should().Be("IListByteArrayArray"); } } \ No newline at end of file