Skip to content

Commit 1970691

Browse files
committed
Fix bug #100
1 parent 9b260e2 commit 1970691

File tree

7 files changed

+98
-4
lines changed

7 files changed

+98
-4
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ 'windows-latest' ]
17-
dotnet: [ '3.1.301' ]
17+
dotnet: [ '3.1.302' ]
1818

1919
runs-on: ${{ matrix.os }}
2020

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ 'windows-latest' ]
14-
dotnet: [ '3.1.301' ]
14+
dotnet: [ '3.1.302' ]
1515

1616
runs-on: ${{ matrix.os }}
1717

.github/workflows/release-all.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ 'windows-latest' ]
17-
dotnet: [ '3.1.301' ]
17+
dotnet: [ '3.1.302' ]
1818

1919
runs-on: ${{ matrix.os }}
2020

.github/workflows/release-cli.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
matrix:
1313
os: [ 'windows-latest' ]
1414
node: [ 10 ]
15-
dotnet: [ '3.1.301' ]
15+
dotnet: [ '3.1.302' ]
1616
targetFramework: [ 'net461', 'netcoreapp3.1' ]
1717
runtime: [ 'win-x64', 'linux-x64', 'osx-x64' ]
1818

src/Aliencube.AzureFunctions.Extensions.OpenApi.Core/Extensions/TypeExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,26 @@ private static bool IsArrayType(this Type type)
536536
return true;
537537
}
538538

539+
if (type.IsGenericTypeOf(typeof(ICollection<>)))
540+
{
541+
return true;
542+
}
543+
539544
if (type.IsGenericTypeOf(typeof(IEnumerable<>)))
540545
{
541546
return true;
542547
}
543548

549+
if (type.IsGenericTypeOf(typeof(IReadOnlyList<>)))
550+
{
551+
return true;
552+
}
553+
554+
if (type.IsGenericTypeOf(typeof(IReadOnlyCollection<>)))
555+
{
556+
return true;
557+
}
558+
544559
return false;
545560
}
546561

@@ -561,6 +576,16 @@ private static bool IsDictionaryType(this Type type)
561576
return true;
562577
}
563578

579+
if (type.Name.Equals("IReadOnlyDictionary`2", StringComparison.CurrentCultureIgnoreCase))
580+
{
581+
return true;
582+
}
583+
584+
if (type.Name.Equals("KeyValuePair`2", StringComparison.CurrentCultureIgnoreCase))
585+
{
586+
return true;
587+
}
588+
564589
return false;
565590
}
566591

test/Aliencube.AzureFunctions.Extensions.OpenApi.Core.Tests/Visitors/DictionaryObjectTypeVisitorTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public void Given_Type_When_IsNavigatable_Invoked_Then_It_Should_Return_Result(T
4343

4444
[DataTestMethod]
4545
[DataRow(typeof(Dictionary<string, string>), true)]
46+
[DataRow(typeof(IDictionary<string, string>), true)]
47+
[DataRow(typeof(IReadOnlyDictionary<string, string>), true)]
48+
[DataRow(typeof(KeyValuePair<string, string>), true)]
4649
[DataRow(typeof(int), false)]
4750
public void Given_Type_When_IsVisitable_Invoked_Then_It_Should_Return_Result(Type type, bool expected)
4851
{
@@ -53,6 +56,9 @@ public void Given_Type_When_IsVisitable_Invoked_Then_It_Should_Return_Result(Typ
5356

5457
[DataTestMethod]
5558
[DataRow(typeof(Dictionary<string, string>), false)]
59+
[DataRow(typeof(IDictionary<string, string>), false)]
60+
[DataRow(typeof(IReadOnlyDictionary<string, string>), false)]
61+
[DataRow(typeof(KeyValuePair<string, string>), false)]
5662
[DataRow(typeof(int), false)]
5763
public void Given_Type_When_IsParameterVisitable_Invoked_Then_It_Should_Return_Result(Type type, bool expected)
5864
{
@@ -63,6 +69,9 @@ public void Given_Type_When_IsParameterVisitable_Invoked_Then_It_Should_Return_R
6369

6470
[DataTestMethod]
6571
[DataRow(typeof(Dictionary<string, string>), true)]
72+
[DataRow(typeof(IDictionary<string, string>), true)]
73+
[DataRow(typeof(IReadOnlyDictionary<string, string>), true)]
74+
[DataRow(typeof(KeyValuePair<string, string>), true)]
6675
[DataRow(typeof(int), false)]
6776
public void Given_Type_When_IsPayloadVisitable_Invoked_Then_It_Should_Return_Result(Type type, bool expected)
6877
{
@@ -73,7 +82,13 @@ public void Given_Type_When_IsPayloadVisitable_Invoked_Then_It_Should_Return_Res
7382

7483
[DataTestMethod]
7584
[DataRow(typeof(Dictionary<string, string>), "object", null, "string", false, "string", 0)]
85+
[DataRow(typeof(IDictionary<string, string>), "object", null, "string", false, "string", 0)]
86+
[DataRow(typeof(IReadOnlyDictionary<string, string>), "object", null, "string", false, "string", 0)]
87+
[DataRow(typeof(KeyValuePair<string, string>), "object", null, "string", false, "string", 0)]
7688
[DataRow(typeof(Dictionary<string, FakeModel>), "object", null, "object", true, "fakeModel", 1)]
89+
[DataRow(typeof(IDictionary<string, FakeModel>), "object", null, "object", true, "fakeModel", 1)]
90+
[DataRow(typeof(IReadOnlyDictionary<string, FakeModel>), "object", null, "object", true, "fakeModel", 1)]
91+
[DataRow(typeof(KeyValuePair<string, FakeModel>), "object", null, "object", true, "fakeModel", 1)]
7792
public void Given_Type_When_Visit_Invoked_Then_It_Should_Return_Result(Type dictionaryType, string dataType, string dataFormat, string additionalPropertyType, bool isReferential, string referenceId, int expected)
7893
{
7994
var name = "hello";
@@ -118,6 +133,9 @@ public void Given_Attribute_When_Visit_Invoked_Then_It_Should_Return_Result(Open
118133

119134
[DataTestMethod]
120135
[DataRow(typeof(Dictionary<string, string>), "object", null, null)]
136+
[DataRow(typeof(IDictionary<string, string>), "object", null, null)]
137+
[DataRow(typeof(IReadOnlyDictionary<string, string>), "object", null, null)]
138+
[DataRow(typeof(KeyValuePair<string, string>), "object", null, null)]
121139
public void Given_Type_When_ParameterVisit_Invoked_Then_It_Should_Return_Result(Type dictionaryType, string dataType, string dataFormat, OpenApiSchema expected)
122140
{
123141
var result = this._visitor.ParameterVisit(dictionaryType, this._strategy);
@@ -127,7 +145,13 @@ public void Given_Type_When_ParameterVisit_Invoked_Then_It_Should_Return_Result(
127145

128146
[DataTestMethod]
129147
[DataRow(typeof(Dictionary<string, string>), "object", null, "string", "string")]
148+
[DataRow(typeof(IDictionary<string, string>), "object", null, "string", "string")]
149+
[DataRow(typeof(IReadOnlyDictionary<string, string>), "object", null, "string", "string")]
150+
[DataRow(typeof(KeyValuePair<string, string>), "object", null, "string", "string")]
130151
[DataRow(typeof(Dictionary<string, FakeModel>), "object", null, "object", "fakeModel")]
152+
[DataRow(typeof(IDictionary<string, FakeModel>), "object", null, "object", "fakeModel")]
153+
[DataRow(typeof(IReadOnlyDictionary<string, FakeModel>), "object", null, "object", "fakeModel")]
154+
[DataRow(typeof(KeyValuePair<string, FakeModel>), "object", null, "object", "fakeModel")]
131155
public void Given_Type_When_PayloadVisit_Invoked_Then_It_Should_Return_Result(Type dictionaryType, string dataType, string dataFormat, string additionalPropertyType, string referenceId)
132156
{
133157
var result = this._visitor.PayloadVisit(dictionaryType, this._strategy);

test/Aliencube.AzureFunctions.Extensions.OpenApi.Core.Tests/Visitors/ListObjectTypeVisitorTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public void Given_Type_When_IsNavigatable_Invoked_Then_It_Should_Return_Result(T
4343

4444
[DataTestMethod]
4545
[DataRow(typeof(List<string>), true)]
46+
[DataRow(typeof(IList<string>), true)]
47+
[DataRow(typeof(ICollection<string>), true)]
48+
[DataRow(typeof(IEnumerable<string>), true)]
49+
[DataRow(typeof(IReadOnlyList<string>), true)]
50+
[DataRow(typeof(IReadOnlyCollection<string>), true)]
4651
[DataRow(typeof(int), false)]
4752
public void Given_Type_When_IsVisitable_Invoked_Then_It_Should_Return_Result(Type type, bool expected)
4853
{
@@ -53,6 +58,11 @@ public void Given_Type_When_IsVisitable_Invoked_Then_It_Should_Return_Result(Typ
5358

5459
[DataTestMethod]
5560
[DataRow(typeof(List<string>), true)]
61+
[DataRow(typeof(IList<string>), true)]
62+
[DataRow(typeof(ICollection<string>), true)]
63+
[DataRow(typeof(IEnumerable<string>), true)]
64+
[DataRow(typeof(IReadOnlyList<string>), true)]
65+
[DataRow(typeof(IReadOnlyCollection<string>), true)]
5666
[DataRow(typeof(int), false)]
5767
public void Given_Type_When_IsParameterVisitable_Invoked_Then_It_Should_Return_Result(Type type, bool expected)
5868
{
@@ -63,6 +73,11 @@ public void Given_Type_When_IsParameterVisitable_Invoked_Then_It_Should_Return_R
6373

6474
[DataTestMethod]
6575
[DataRow(typeof(List<string>), true)]
76+
[DataRow(typeof(IList<string>), true)]
77+
[DataRow(typeof(ICollection<string>), true)]
78+
[DataRow(typeof(IEnumerable<string>), true)]
79+
[DataRow(typeof(IReadOnlyList<string>), true)]
80+
[DataRow(typeof(IReadOnlyCollection<string>), true)]
6681
[DataRow(typeof(int), false)]
6782
public void Given_Type_When_IsPayloadVisitable_Invoked_Then_It_Should_Return_Result(Type type, bool expected)
6883
{
@@ -73,7 +88,17 @@ public void Given_Type_When_IsPayloadVisitable_Invoked_Then_It_Should_Return_Res
7388

7489
[DataTestMethod]
7590
[DataRow(typeof(List<string>), "array", null, "string", false, "string", 0)]
91+
[DataRow(typeof(IList<string>), "array", null, "string", false, "string", 0)]
92+
[DataRow(typeof(ICollection<string>), "array", null, "string", false, "string", 0)]
93+
[DataRow(typeof(IEnumerable<string>), "array", null, "string", false, "string", 0)]
94+
[DataRow(typeof(IReadOnlyList<string>), "array", null, "string", false, "string", 0)]
95+
[DataRow(typeof(IReadOnlyCollection<string>), "array", null, "string", false, "string", 0)]
7696
[DataRow(typeof(List<FakeModel>), "array", null, "object", true, "fakeModel", 1)]
97+
[DataRow(typeof(IList<FakeModel>), "array", null, "object", true, "fakeModel", 1)]
98+
[DataRow(typeof(ICollection<FakeModel>), "array", null, "object", true, "fakeModel", 1)]
99+
[DataRow(typeof(IEnumerable<FakeModel>), "array", null, "object", true, "fakeModel", 1)]
100+
[DataRow(typeof(IReadOnlyList<FakeModel>), "array", null, "object", true, "fakeModel", 1)]
101+
[DataRow(typeof(IReadOnlyCollection<FakeModel>), "array", null, "object", true, "fakeModel", 1)]
77102
public void Given_Type_When_Visit_Invoked_Then_It_Should_Return_Result(Type listType, string dataType, string dataFormat, string itemType, bool isReferential, string referenceId, int expected)
78103
{
79104
var name = "hello";
@@ -118,7 +143,17 @@ public void Given_Attribute_When_Visit_Invoked_Then_It_Should_Return_Result(Open
118143

119144
[DataTestMethod]
120145
[DataRow(typeof(List<string>), "array", null, "string", false)]
146+
[DataRow(typeof(IList<string>), "array", null, "string", false)]
147+
[DataRow(typeof(ICollection<string>), "array", null, "string", false)]
148+
[DataRow(typeof(IEnumerable<string>), "array", null, "string", false)]
149+
[DataRow(typeof(IReadOnlyList<string>), "array", null, "string", false)]
150+
[DataRow(typeof(IReadOnlyCollection<string>), "array", null, "string", false)]
121151
[DataRow(typeof(List<FakeModel>), "array", null, "object", true)]
152+
[DataRow(typeof(IList<FakeModel>), "array", null, "object", true)]
153+
[DataRow(typeof(ICollection<FakeModel>), "array", null, "object", true)]
154+
[DataRow(typeof(IEnumerable<FakeModel>), "array", null, "object", true)]
155+
[DataRow(typeof(IReadOnlyList<FakeModel>), "array", null, "object", true)]
156+
[DataRow(typeof(IReadOnlyCollection<FakeModel>), "array", null, "object", true)]
122157
public void Given_Type_When_ParameterVisit_Invoked_Then_It_Should_Return_Result(Type listType, string dataType, string dataFormat, string itemType, bool isItemToBeNull)
123158
{
124159
var result = this._visitor.ParameterVisit(listType, this._strategy);
@@ -135,7 +170,17 @@ public void Given_Type_When_ParameterVisit_Invoked_Then_It_Should_Return_Result(
135170

136171
[DataTestMethod]
137172
[DataRow(typeof(List<string>), "array", null, "string", "string")]
173+
[DataRow(typeof(IList<string>), "array", null, "string", "string")]
174+
[DataRow(typeof(ICollection<string>), "array", null, "string", "string")]
175+
[DataRow(typeof(IEnumerable<string>), "array", null, "string", "string")]
176+
[DataRow(typeof(IReadOnlyList<string>), "array", null, "string", "string")]
177+
[DataRow(typeof(IReadOnlyCollection<string>), "array", null, "string", "string")]
138178
[DataRow(typeof(List<FakeModel>), "array", null, "object", "fakeModel")]
179+
[DataRow(typeof(IList<FakeModel>), "array", null, "object", "fakeModel")]
180+
[DataRow(typeof(ICollection<FakeModel>), "array", null, "object", "fakeModel")]
181+
[DataRow(typeof(IEnumerable<FakeModel>), "array", null, "object", "fakeModel")]
182+
[DataRow(typeof(IReadOnlyList<FakeModel>), "array", null, "object", "fakeModel")]
183+
[DataRow(typeof(IReadOnlyCollection<FakeModel>), "array", null, "object", "fakeModel")]
139184
public void Given_Type_When_PayloadVisit_Invoked_Then_It_Should_Return_Result(Type listType, string dataType, string dataFormat, string itemType, string referenceId)
140185
{
141186
var result = this._visitor.PayloadVisit(listType, this._strategy);

0 commit comments

Comments
 (0)