Skip to content

Commit d3e5b10

Browse files
committed
Fixed instantiation of Components in V2 deserializer
1 parent 9f5adb3 commit d3e5b10

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ internal static partial class OpenApiV2Deserializer
4545
{"paths", (o, n) => o.Paths = LoadPaths(n)},
4646
{
4747
"definitions",
48-
(o, n) => o.Components.Schemas = n.CreateMapWithReference(
48+
(o, n) => {
49+
o.Components = new OpenApiComponents();
50+
o.Components.Schemas = n.CreateMapWithReference(
4951
ReferenceType.Schema,
5052
"#/definitions/",
51-
LoadSchema)
53+
LoadSchema);
54+
}
5255
},
5356
{
5457
"parameters",

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
4141
/// <summary>
4242
/// An element to hold various schemas for the specification.
4343
/// </summary>
44-
public OpenApiComponents Components { get; set; } = new OpenApiComponents();
44+
public OpenApiComponents Components { get; set; }
4545

4646
/// <summary>
4747
/// A declaration of which security mechanisms can be used across the API.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ComparisonTests
1818
[Theory]
1919
[InlineData("minimal")]
2020
[InlineData("basic")]
21-
// [InlineData("definitions")] Currently broken due to V3 references not behaving the same as V2
21+
//[InlineData("definitions")] //Currently broken due to V3 references not behaving the same as V2
2222
public void EquivalentV2AndV3DocumentsShouldProductEquivalentObjects(string fileName)
2323
{
2424
using (var streamV2 = File.OpenRead(Path.Combine(SampleFolderPath, $"{fileName}.v2.yaml")))

0 commit comments

Comments
 (0)