Skip to content

Commit 469a55a

Browse files
committed
Changed OpenApiDocument.Paths to be null by default
1 parent e058e01 commit 469a55a

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible
2929
/// <summary>
3030
/// REQUIRED. The available paths and operations for the API.
3131
/// </summary>
32-
public OpenApiPaths Paths { get; set; } = new OpenApiPaths();
32+
public OpenApiPaths Paths { get; set; }
3333

3434
/// <summary>
3535
/// An element to hold various schemas for the specification.

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public void ParseDocumentFromInlineStringShouldSucceed()
4646
{
4747
Title = "Simple Document",
4848
Version = "0.9.1"
49-
}
49+
},
50+
Paths = new OpenApiPaths()
5051
});
5152

5253
context.ShouldBeEquivalentTo(
@@ -83,7 +84,8 @@ public void ParseBasicDocumentWithMultipleServersShouldSucceed()
8384
Url = new Uri("https://www.example.org/api").ToString(),
8485
Description = "The https endpoint"
8586
}
86-
}
87+
},
88+
Paths = new OpenApiPaths()
8789
});
8890
}
8991
}
@@ -101,7 +103,8 @@ public void ParseBrokenMinimalDocumentShouldYieldExpectedDiagnostic()
101103
Info = new OpenApiInfo
102104
{
103105
Version = "0.9"
104-
}
106+
},
107+
Paths = new OpenApiPaths()
105108
});
106109

107110
diagnostic.ShouldBeEquivalentTo(
@@ -130,7 +133,8 @@ public void ParseMinimalDocumentShouldSucceed()
130133
{
131134
Title = "Simple Document",
132135
Version = "0.9.1"
133-
}
136+
},
137+
Paths = new OpenApiPaths()
134138
});
135139

136140
diagnostic.ShouldBeEquivalentTo(

test/Microsoft.OpenApi.Tests/Services/OpenApiValidatorTests.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public void ResponseMustHaveADescription()
3535
Title = "foo",
3636
Version = "1.2.2"
3737
};
38+
openApiDocument.Paths = new OpenApiPaths();
3839
openApiDocument.Paths.Add(
3940
"/test",
4041
new OpenApiPathItem
@@ -66,23 +67,26 @@ public void ResponseMustHaveADescription()
6667
[Fact]
6768
public void ServersShouldBeReferencedByIndex()
6869
{
69-
var openApiDocument = new OpenApiDocument();
70-
openApiDocument.Info = new OpenApiInfo()
70+
var openApiDocument = new OpenApiDocument
7171
{
72-
Title = "foo",
73-
Version = "1.2.2"
74-
};
75-
openApiDocument.Servers = new List<OpenApiServer> {
72+
Info = new OpenApiInfo()
73+
{
74+
Title = "foo",
75+
Version = "1.2.2"
76+
},
77+
Servers = new List<OpenApiServer> {
7678
new OpenApiServer
7779
{
7880
Url = "http://example.org"
7981
},
8082
new OpenApiServer
8183
{
8284

83-
}
85+
},
86+
},
87+
Paths = new OpenApiPaths()
8488
};
85-
89+
8690
var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet());
8791
var walker = new OpenApiWalker(validator);
8892
walker.Walk(openApiDocument);
@@ -111,11 +115,14 @@ public void ValidateCustomExtension()
111115
}
112116
}));
113117

114-
var openApiDocument = new OpenApiDocument();
115-
openApiDocument.Info = new OpenApiInfo()
118+
var openApiDocument = new OpenApiDocument
116119
{
117-
Title = "foo",
118-
Version = "1.2.2"
120+
Info = new OpenApiInfo()
121+
{
122+
Title = "foo",
123+
Version = "1.2.2"
124+
},
125+
Paths = new OpenApiPaths()
119126
};
120127

121128
var fooExtension = new FooExtension()

test/Microsoft.OpenApi.Tests/Walkers/WalkerLocationTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public void LocateTopLevelObjects()
2323

2424
locator.Locations.ShouldBeEquivalentTo(new List<string> {
2525
"#/servers",
26-
"#/paths",
2726
"#/tags"
2827
});
2928
}
@@ -37,6 +36,7 @@ public void LocateTopLevelArrayItems()
3736
new OpenApiServer(),
3837
new OpenApiServer()
3938
},
39+
Paths = new OpenApiPaths(),
4040
Tags = new List<OpenApiTag>()
4141
{
4242
new OpenApiTag()
@@ -61,6 +61,7 @@ public void LocateTopLevelArrayItems()
6161
public void LocatePathOperationContentSchema()
6262
{
6363
var doc = new OpenApiDocument();
64+
doc.Paths = new OpenApiPaths();
6465
doc.Paths.Add("/test", new OpenApiPathItem()
6566
{
6667
Operations = new Dictionary<OperationType, OpenApiOperation>()
@@ -124,6 +125,7 @@ public void WalkDOMWithCycles()
124125

125126
var doc = new OpenApiDocument()
126127
{
128+
Paths = new OpenApiPaths(),
127129
Components = new OpenApiComponents()
128130
{
129131
Schemas = new Dictionary<string, OpenApiSchema>

0 commit comments

Comments
 (0)