Skip to content

Commit

Permalink
Add support for IAsyncEnumerable for Newtonsoft serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Apr 13, 2024
1 parent 18da71a commit 5de599a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
using DotSwashbuckle.AspNetCore.SwaggerGen;
using System.Collections;

namespace DotSwashbuckle.AspNetCore.Newtonsoft
{
Expand Down Expand Up @@ -71,6 +72,14 @@ public DataContract GetDataContractForType(Type type)
jsonConverter: JsonConverterFunc);
}

if (JsonSerializerDataContractResolver.IsSupportedCollection(type, out Type itemType))
{
return DataContract.ForArray(
underlyingType: type,
itemType: itemType,
jsonConverter: JsonConverterFunc);
}

if (jsonContract is JsonDictionaryContract jsonDictionaryContract)
{
var keyType = jsonDictionaryContract.DictionaryKeyType ?? typeof(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public bool IsSupportedDictionary(Type type, out Type keyType, out Type valueTyp
return false;
}

public bool IsSupportedCollection(Type type, out Type itemType)
public static bool IsSupportedCollection(Type type, out Type itemType)
{
if (type.IsConstructedFrom(typeof(IEnumerable<>), out Type constructedType))
{
Expand Down

0 comments on commit 5de599a

Please sign in to comment.