Skip to content

Commit 3445c1d

Browse files
committed
Log warning to console if url in collection isn't in the input OpenApi doc and continue processing the rest of the urls and add unit test
1 parent 3350d86 commit 3445c1d

File tree

4 files changed

+171
-0
lines changed

4 files changed

+171
-0
lines changed

src/Microsoft.OpenApi/Services/OpenApiFilterService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public static class OpenApiFilterService
8181
var openApiOperations = GetOpenApiOperations(rootNode, url, apiVersion);
8282
if (openApiOperations == null)
8383
{
84+
Console.WriteLine($"The url {url} could not be found in the OpenApi description");
8485
continue;
8586
}
8687

test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
<None Update="UtilityFiles\postmanCollection_ver3.json">
4848
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
4949
</None>
50+
<None Update="UtilityFiles\postmanCollection_ver4.json">
51+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
52+
</None>
5053
<None Update="UtilityFiles\Todo.xml">
5154
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
5255
</None>

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,28 @@ public void ThrowsExceptionWhenUrlsInCollectionAreMissingFromSourceDocument()
103103
Assert.Equal("The urls in the Postman collection supplied could not be found.", message);
104104
}
105105

106+
[Fact]
107+
public void ContinueProcessingWhenUrlsInCollectionAreMissingFromSourceDocument()
108+
{
109+
// Arrange
110+
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UtilityFiles\\postmanCollection_ver4.json");
111+
var fileInput = new FileInfo(filePath);
112+
var stream = fileInput.OpenRead();
113+
114+
// Act
115+
var requestUrls = OpenApiService.ParseJsonCollectionFile(stream, _logger);
116+
var pathCount = requestUrls.Count;
117+
var predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: _openApiDocumentMock);
118+
var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(_openApiDocumentMock, predicate);
119+
var subsetPathCount = subsetOpenApiDocument.Paths.Count;
120+
121+
// Assert
122+
Assert.NotNull(subsetOpenApiDocument);
123+
Assert.NotEmpty(subsetOpenApiDocument.Paths);
124+
Assert.Equal(2, subsetPathCount);
125+
Assert.NotEqual(pathCount, subsetPathCount);
126+
}
127+
106128
[Fact]
107129
public void ThrowsInvalidOperationExceptionInCreatePredicateWhenInvalidArgumentsArePassed()
108130
{
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
{
2+
"info": {
3+
"_postman_id": "43402ca3-f018-7c9b-2315-f176d9b171a3",
4+
"name": "Graph-Collection",
5+
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
6+
},
7+
"item": [
8+
{
9+
"name": "users-GET",
10+
"request": {
11+
"method": "GET",
12+
"url": {
13+
"raw": "https://graph.microsoft.com/v1.0/users",
14+
"protocol": "https",
15+
"host": [
16+
"graph",
17+
"microsoft",
18+
"com"
19+
],
20+
"path": [
21+
"v1.0",
22+
"users"
23+
]
24+
}
25+
}
26+
},
27+
{
28+
"name": "users-POST",
29+
"request": {
30+
"method": "POST",
31+
"url": {
32+
"raw": "https://graph.microsoft.com/v1.0/users",
33+
"protocol": "https",
34+
"host": [
35+
"graph",
36+
"microsoft",
37+
"com"
38+
],
39+
"path": [
40+
"v1.0",
41+
"users"
42+
]
43+
}
44+
}
45+
},
46+
{
47+
"name": "/appCatalogs",
48+
"request": {
49+
"method": "GET",
50+
"url": {
51+
"raw": "https://graph.microsoft.com/v1.0/appCatalogs",
52+
"protocol": "https",
53+
"host": [
54+
"graph",
55+
"microsoft",
56+
"com"
57+
],
58+
"path": [
59+
"v1.0",
60+
"appCatalogs"
61+
]
62+
}
63+
}
64+
},
65+
{
66+
"name": "/agreementAcceptances",
67+
"request": {
68+
"method": "GET",
69+
"url": {
70+
"raw": "https://graph.microsoft.com/v1.0/agreementAcceptances",
71+
"protocol": "https",
72+
"host": [
73+
"graph",
74+
"microsoft",
75+
"com"
76+
],
77+
"path": [
78+
"v1.0",
79+
"agreementAcceptances"
80+
]
81+
}
82+
}
83+
},
84+
{
85+
"name": "{user-id}-GET",
86+
"request": {
87+
"method": "GET",
88+
"url": {
89+
"raw": "https://graph.microsoft.com/v1.0/users/{user-id}",
90+
"protocol": "https",
91+
"host": [
92+
"graph",
93+
"microsoft",
94+
"com"
95+
],
96+
"path": [
97+
"v1.0",
98+
"users",
99+
"{user-id}"
100+
]
101+
}
102+
}
103+
},
104+
{
105+
"name": "{user-id}-PATCH",
106+
"request": {
107+
"method": "PATCH",
108+
"url": {
109+
"raw": "https://graph.microsoft.com/v1.0/users/{user-id}",
110+
"protocol": "https",
111+
"host": [
112+
"graph",
113+
"microsoft",
114+
"com"
115+
],
116+
"path": [
117+
"v1.0",
118+
"users",
119+
"{user-id}"
120+
]
121+
}
122+
}
123+
},
124+
{
125+
"name": "{user-id}-DELETE",
126+
"request": {
127+
"method": "DELETE",
128+
"url": {
129+
"raw": "https://graph.microsoft.com/v1.0/users/{user-id}",
130+
"protocol": "https",
131+
"host": [
132+
"graph",
133+
"microsoft",
134+
"com"
135+
],
136+
"path": [
137+
"v1.0",
138+
"users",
139+
"{user-id}"
140+
]
141+
}
142+
}
143+
}
144+
]
145+
}

0 commit comments

Comments
 (0)