diff --git a/src/NJsonSchema.Tests/Generation/ArrayGenerationTests.cs b/src/NJsonSchema.Tests/Generation/ArrayGenerationTests.cs index 32cd856a6..07232d097 100644 --- a/src/NJsonSchema.Tests/Generation/ArrayGenerationTests.cs +++ b/src/NJsonSchema.Tests/Generation/ArrayGenerationTests.cs @@ -80,5 +80,38 @@ public async Task When_class_inherits_from_list_then_schema_is_inlined_and_type_ Assert.Equal(JsonObjectType.Array, schema.Definitions["SomeModelCollectionResponse"].Type); Assert.NotNull(schema.Definitions["SomeModelCollectionResponse"].Item); } + +#if NET5_0 + + public class ClassWithAsyncEnumerable + { + public IAsyncEnumerable AsyncApples { get; set; } + + public List AppleList { get; set; } + } + + public class Apple + { + public string Name { get; set; } + } + + [Fact] + public async Task When_property_is_async_numerable_then_item_type_is_correct() + { + //// Act + var schema = JsonSchema.FromType(new JsonSchemaGeneratorSettings { SchemaType = SchemaType.OpenApi3 }); + var json = schema.ToJson(); + + //// Assert + var asyncProperty = schema.ActualProperties["AsyncApples"].ActualTypeSchema; + Assert.Equal(JsonObjectType.Array, asyncProperty.Type); + Assert.True(asyncProperty.Item.HasReference); + + var listProperty = schema.ActualProperties["AppleList"].ActualTypeSchema; + Assert.Equal(JsonObjectType.Array, listProperty.Type); + Assert.True(listProperty.Item.HasReference); + } + +#endif } } \ No newline at end of file diff --git a/src/NJsonSchema/Generation/JsonSchemaGenerator.cs b/src/NJsonSchema/Generation/JsonSchemaGenerator.cs index 6bbc58c60..6a857ceeb 100644 --- a/src/NJsonSchema/Generation/JsonSchemaGenerator.cs +++ b/src/NJsonSchema/Generation/JsonSchemaGenerator.cs @@ -582,7 +582,10 @@ protected virtual void GenerateArray( typeDescription.ApplyType(schema); var jsonSchemaAttribute = contextualType.GetTypeAttribute(); - var itemType = jsonSchemaAttribute?.ArrayItem.ToContextualType() ?? contextualType.EnumerableItemType; + var itemType = jsonSchemaAttribute?.ArrayItem.ToContextualType() ?? + contextualType.EnumerableItemType ?? + contextualType.GenericArguments.FirstOrDefault(); + if (itemType != null) { var itemIsNullable = contextualType.GetContextAttribute() != null ||