diff --git a/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/TypeExtensions.cs b/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/TypeExtensions.cs index cf2a7b6f..dc819056 100644 --- a/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/TypeExtensions.cs +++ b/src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/TypeExtensions.cs @@ -460,8 +460,8 @@ public static Type GetUnderlyingType(this Type type) } if (type.IsOpenApiArray()) - { - underlyingType = type.GetElementType() ?? type.GetGenericArguments()[0]; + { + underlyingType = type.GetElementType() ?? (type.GetGenericArguments() != null && type.GetGenericArguments().Length > 0 ? type.GetGenericArguments()[0] : (type.BaseType.GetGenericArguments() != null && type.BaseType.GetGenericArguments().Length > 0 ? type.BaseType.GetGenericArguments()[0] :type.GetInterfaces()[0].GetGenericArguments()[0])) ; } if (type.IsOpenApiDictionary()) @@ -557,7 +557,7 @@ public static Type GetOpenApiSubType(this Type type) if (type.IsArrayType()) { - return type.GetGenericArguments()[0]; + return type.GetGenericArguments() != null && type.GetGenericArguments().Length > 0 ? type.GetGenericArguments()[0] : (type.BaseType.GetGenericArguments() != null && type.BaseType.GetGenericArguments().Length > 0 ? type.BaseType.GetGenericArguments()[0] : type.GetInterfaces()[0].GetGenericArguments()[0]); } return null; diff --git a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_ArrayObject_Tests.cs b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_ArrayObject_Tests.cs index da6a5a37..8b53ed96 100644 --- a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_ArrayObject_Tests.cs +++ b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_ArrayObject_Tests.cs @@ -76,6 +76,7 @@ public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchema(string @ [DataRow("arrayObjectModel", "object", "decimalValue", "array")] [DataRow("arrayObjectModel", "object", "stringObjectValue", "array")] [DataRow("arrayObjectModel", "object", "objectArrayValue", "array")] + [DataRow("arrayObjectModel", "object", "nestedCollectionValue", "array")] public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchemaProperty(string @ref, string refType, string propertyName, string propertyType) { var properties = this._doc["components"]["schemas"][@ref]["properties"]; @@ -107,6 +108,7 @@ public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchemaPropertyI [DataTestMethod] [DataRow("arrayObjectModel", "object", "stringObjectValue", "array", "stringObjectModel")] [DataRow("arrayObjectModel", "object", "objectArrayValue", "array", "list_object")] + [DataRow("arrayObjectModel", "object", "nestedCollectionValue", "array", "collection_userDefine")] public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchemaPropertyItemReference(string @ref, string refType, string propertyName, string propertyType, string itemRef) { var items = this._doc["components"]["schemas"][@ref]["properties"][propertyName]["items"]; diff --git a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Models/ArrayObjectModel.cs b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Models/ArrayObjectModel.cs index f7a0674b..2e06f3a9 100644 --- a/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Models/ArrayObjectModel.cs +++ b/test-integration/Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp/Models/ArrayObjectModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Collections.ObjectModel; namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp.Models { @@ -14,5 +15,11 @@ public class ArrayObjectModel public ISet StringObjectValue { get; set; } public List ObjectArrayValue { get; set; } + + public Collection_Udf NestedCollectionValue { get; set; } } + + public class UserDefine { } + + public class Collection_Udf : Collection> { } } diff --git a/test/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes/FakeAliasInheritanceModel.cs b/test/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes/FakeAliasInheritanceModel.cs new file mode 100644 index 00000000..b6f09bf4 --- /dev/null +++ b/test/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes/FakeAliasInheritanceModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests.Fakes +{ + public class FakeAliasInheritanceModel : Collection> + { + + } +} diff --git a/test/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests/Extensions/TypeExtensionsTests.cs b/test/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests/Extensions/TypeExtensionsTests.cs index 0d6a81d7..04a76796 100644 --- a/test/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests/Extensions/TypeExtensionsTests.cs +++ b/test/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Tests/Extensions/TypeExtensionsTests.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; - +using System.Collections.ObjectModel; using FluentAssertions; using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions; @@ -119,6 +119,7 @@ public void Given_NullableType_When_GetUnderlyingType_Invoked_Then_It_Should_Ret [DataRow(typeof(List), typeof(int))] [DataRow(typeof(List), typeof(bool))] [DataRow(typeof(List), typeof(FakeModel))] + [DataRow(typeof(FakeAliasInheritanceModel), typeof(Collection))] public void Given_ListType_When_GetUnderlyingType_Invoked_Then_It_Should_Return_Result(Type type, Type expected) { var result = TypeExtensions.GetUnderlyingType(type);