Skip to content

Commit ae0c646

Browse files
committed
Fixed issue with schema enum
1 parent f818b95 commit ae0c646

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

src/Microsoft.OpenApi.Readers/ParseNodes/ListNode.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ public override List<T> CreateList<T>(Func<MapNode, T> map)
3838
.ToList();
3939
}
4040

41+
public override List<IOpenApiAny> CreateListOfAny()
42+
{
43+
var yamlSequence = _nodeList;
44+
if (yamlSequence == null)
45+
{
46+
throw new OpenApiException(
47+
$"Expected list at line {_nodeList.Start.Line}");
48+
}
49+
50+
return yamlSequence.Select(n => ParseNode.Create(Context, Diagnostic,n).CreateAny())
51+
.Where(i => i != null)
52+
.ToList();
53+
}
54+
4155
public override List<T> CreateSimpleList<T>(Func<ValueNode, T> map)
4256
{
4357
var yamlSequence = _nodeList;

src/Microsoft.OpenApi.Readers/ParseNodes/ParseNode.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,11 @@ public virtual string GetScalarValue()
114114
{
115115
throw new OpenApiException("Cannot get scalar value");
116116
}
117+
118+
public virtual List<IOpenApiAny> CreateListOfAny()
119+
{
120+
throw new OpenApiException("Cannot create list of any from here");
121+
}
122+
117123
}
118124
}

src/Microsoft.OpenApi.Readers/V2/OpenApiSchemaDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ internal static partial class OpenApiV2Deserializer
109109
{
110110
"enum", (o, n) =>
111111
{
112-
o.Enum = n.CreateList<IOpenApiAny>(s => s.CreateAny());
112+
o.Enum = n.CreateListOfAny();
113113
}
114114
},
115115

test/Microsoft.OpenApi.SmokeTests/ApiGurus.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ JToken GetProp(JToken obj, string prop)
7070
}
7171

7272

73-
// [Theory(DisplayName = "APIs.guru")]
74-
// [MemberData(nameof(GetSchemas))]
73+
[Theory(DisplayName = "APIs.guru")]
74+
[MemberData(nameof(GetSchemas))]
7575
public async Task EnsureThatICouldParse(string url)
7676
{
7777
var stopwatch = new Stopwatch();
@@ -87,19 +87,24 @@ public async Task EnsureThatICouldParse(string url)
8787

8888
stopwatch.Start();
8989

90-
var openApiDocument = new OpenApiStreamReader().Read(stream, out var diagnostic);
90+
var reader = new OpenApiStreamReader(new OpenApiReaderSettings() {
91+
});
92+
var openApiDocument = reader.Read(stream, out var diagnostic);
9193

92-
output.WriteLine(String.Join("\n", diagnostic.Errors));
93-
Assert.Equal(OpenApiSpecVersion.OpenApi2_0, diagnostic.SpecificationVersion);
94-
Assert.Equal(0, diagnostic.Errors.Count);
95-
96-
Assert.NotNull(openApiDocument);
94+
if (diagnostic.Errors.Count > 0)
95+
{
96+
output.WriteLine($"Errors parsing {url}");
97+
output.WriteLine(String.Join("\n", diagnostic.Errors));
98+
Assert.True(false);
99+
}
100+
101+
Assert.NotNull(openApiDocument);
97102
stopwatch.Stop();
98103
output.WriteLine($"Parsing {url} took {stopwatch.ElapsedMilliseconds} ms.");
99104
}
100105

101-
[Theory(DisplayName = "APIs.guru")]
102-
[MemberData(nameof(GetSchemas))]
106+
//[Theory(DisplayName = "APIs.guru")]
107+
//[MemberData(nameof(GetSchemas))]
103108
public async Task EnsureAllErrorsAreHandled(string url)
104109
{
105110
var stopwatch = new Stopwatch();

0 commit comments

Comments
 (0)