Skip to content

Commit c17a87e

Browse files
committed
Clean up code and refactor failing tests
1 parent 9d49a8b commit c17a87e

File tree

15 files changed

+53
-173
lines changed

15 files changed

+53
-173
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public static JsonNode GetSpecificOpenApiAny(JsonNode jsonNode, OpenApiSchema sc
8181
return jsonNode;
8282
}
8383

84-
var value = jsonValue.ToJsonString();
84+
var value = jsonValue.GetScalarValue();
8585
var type = schema?.Type;
8686
var format = schema?.Format;
8787

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System.Globalization;
5+
using System;
46
using System.Text.Json.Nodes;
57
using Microsoft.OpenApi.Readers.Exceptions;
68

@@ -22,7 +24,7 @@ public ValueNode(ParsingContext context, JsonNode node) : base(
2224

2325
public override string GetScalarValue()
2426
{
25-
return _node.GetScalarValue();
27+
return Convert.ToString(_node.GetValue<object>(), CultureInfo.InvariantCulture);
2628
}
2729

2830
/// <summary>

src/Microsoft.OpenApi.Readers/YamlHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System.Globalization;
5+
using System;
46
using System.IO;
57
using System.Linq;
68
using System.Text.Json.Nodes;
9+
using System.Xml.Linq;
710
using SharpYaml.Serialization;
811

912
namespace Microsoft.OpenApi.Readers
@@ -19,7 +22,7 @@ public static string GetScalarValue(this JsonNode node)
1922
//throw new OpenApiException($"Expected scalar at line {node.Start.Line}");
2023
}
2124

22-
return scalarNode?.GetScalarValue();
25+
return Convert.ToString(scalarNode?.GetValue<object>(), CultureInfo.InvariantCulture);
2326
}
2427

2528
public static JsonNode ParseJsonString(string yamlString)

test/Microsoft.OpenApi.Readers.Tests/ParseNodes/OpenApiAnyConverterTests.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Globalization;
66
using System.IO;
77
using System.Linq;
8+
using System.Text.Json;
89
using System.Text.Json.Nodes;
910
using FluentAssertions;
1011
using Microsoft.OpenApi.Models;
@@ -72,20 +73,20 @@ public void ParseObjectAsAnyShouldSucceed()
7273
};
7374

7475
anyMap = OpenApiAnyConverter.GetSpecificOpenApiAny(anyMap, schema);
75-
76+
var expected = new JsonObject
77+
{
78+
["aString"] = "fooBar",
79+
["aInteger"] = 10,
80+
["aDouble"] = 2.34,
81+
["aDateTime"] = DateTimeOffset.Parse("2017-01-01", CultureInfo.InvariantCulture),
82+
["aDate"] = DateTimeOffset.Parse("2017-01-02", CultureInfo.InvariantCulture).Date
83+
};
84+
7685
diagnostic.Errors.Should().BeEmpty();
77-
anyMap.Should().BeEquivalentTo(
78-
new JsonObject
79-
{
80-
["aString"] = "fooBar",
81-
["aInteger"] = 10,
82-
["aDouble"] = 2.34,
83-
["aDateTime"] = DateTimeOffset.Parse("2017-01-01", CultureInfo.InvariantCulture),
84-
["aDate"] = DateTimeOffset.Parse("2017-01-02", CultureInfo.InvariantCulture).Date
85-
});
86+
anyMap.Should().BeEquivalentTo(expected, options => options.IgnoringCyclicReferences());
8687
}
8788

88-
89+
8990
[Fact]
9091
public void ParseNestedObjectAsAnyShouldSucceed()
9192
{
@@ -261,7 +262,7 @@ public void ParseNestedObjectAsAnyShouldSucceed()
261262
},
262263
["aDouble"] = 2.34,
263264
["aDateTime"] = DateTimeOffset.Parse("2017-01-01", CultureInfo.InvariantCulture)
264-
});
265+
}, options => options.IgnoringCyclicReferences());
265266
}
266267

267268

@@ -416,7 +417,7 @@ public void ParseNestedObjectAsAnyWithPartialSchemaShouldSucceed()
416417
},
417418
["aDouble"] = 2.34,
418419
["aDateTime"] = DateTimeOffset.Parse("2017-01-01", CultureInfo.InvariantCulture)
419-
});
420+
}, options => options.IgnoringCyclicReferences());
420421
}
421422

422423
[Fact]
@@ -508,7 +509,7 @@ public void ParseNestedObjectAsAnyWithoutUsingSchemaShouldSucceed()
508509
},
509510
["aDouble"] = 2.34,
510511
["aDateTime"] = DateTimeOffset.Parse("2017-01-01", CultureInfo.InvariantCulture)
511-
});
512+
}, options => options.IgnoringCyclicReferences());
512513
}
513514
}
514515
}

test/Microsoft.OpenApi.Readers.Tests/ParseNodes/OpenApiAnyTests.cs

Lines changed: 0 additions & 126 deletions
This file was deleted.

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiHeaderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void ParseHeaderWithDefaultShouldSucceed()
3838
Format = "float",
3939
Default = 5
4040
}
41-
});
41+
}, options => options.IgnoringCyclicReferences());
4242
}
4343

4444
[Fact]
@@ -69,7 +69,7 @@ public void ParseHeaderWithEnumShouldSucceed()
6969
9
7070
}
7171
}
72-
});
72+
}, options => options.IgnoringCyclicReferences());
7373
}
7474
}
7575
}

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ public void ParseOperationWithResponseExamplesShouldSucceed()
371371
}
372372
}}
373373
}
374-
}
375-
);
374+
}, options => options.IgnoringCyclicReferences());
376375
}
377376
}
378377
}

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiParameterTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void ParseHeaderParameterShouldSucceed()
166166
new JsonArray() { 3, 4 }
167167
}
168168
}
169-
});
169+
}, options => options.IgnoringCyclicReferences());
170170
}
171171

172172
[Fact]
@@ -209,7 +209,7 @@ public void ParseHeaderParameterWithIncorrectDataTypeShouldSucceed()
209209
new JsonArray() { "3", "4" }
210210
}
211211
}
212-
});
212+
}, options => options.IgnoringCyclicReferences());
213213
}
214214

215215
[Fact]
@@ -345,9 +345,9 @@ public void ParseParameterWithDefaultShouldSucceed()
345345
{
346346
Type = "number",
347347
Format = "float",
348-
Default = 5.0
348+
Default = 5
349349
}
350-
});
350+
}, options => options.IgnoringCyclicReferences());
351351
}
352352

353353
[Fact]
@@ -375,9 +375,9 @@ public void ParseParameterWithEnumShouldSucceed()
375375
{
376376
Type = "number",
377377
Format = "float",
378-
Enum = {7.0, 8.0, 9.0 }
378+
Enum = {7, 8, 9 }
379379
}
380-
});
380+
}, options => options.IgnoringCyclicReferences());
381381
}
382382
}
383383
}

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public void ParseSchemaWithDefaultShouldSucceed()
3434
{
3535
Type = "number",
3636
Format = "float",
37-
Default = 5.0
38-
});
37+
Default = 5
38+
}, options => options.IgnoringCyclicReferences());
3939
}
4040

4141
[Fact]
@@ -57,8 +57,8 @@ public void ParseSchemaWithExampleShouldSucceed()
5757
{
5858
Type = "number",
5959
Format = "float",
60-
Example = 5.0
61-
});
60+
Example = 5
61+
}, options => options.IgnoringCyclicReferences());
6262
}
6363

6464
[Fact]
@@ -81,7 +81,7 @@ public void ParseSchemaWithEnumShouldSucceed()
8181
Type = "number",
8282
Format = "float",
8383
Enum = {7, 8, 9}
84-
});
84+
}, options => options.IgnoringCyclicReferences());
8585
}
8686
}
8787
}

test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ public void HeaderParameterShouldAllowExample()
13111311
Type = ReferenceType.Header,
13121312
Id = "example-header"
13131313
}
1314-
});
1314+
}, options => options.IgnoringCyclicReferences());
13151315

13161316
var examplesHeader = openApiDoc.Components?.Headers?["examples-header"];
13171317
Assert.NotNull(examplesHeader);
@@ -1348,7 +1348,7 @@ public void HeaderParameterShouldAllowExample()
13481348
Type = ReferenceType.Header,
13491349
Id = "examples-header"
13501350
}
1351-
});
1351+
}, options => options.IgnoringCyclicReferences());
13521352
}
13531353
}
13541354

0 commit comments

Comments
 (0)