Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Log warning to console if url in collection isn't in the input OpenAp…
…i doc and continue processing the rest of the urls and add unit test
  • Loading branch information
MaggieKimani1 committed Mar 15, 2022
commit 3445c1d3199ebd8dc598d8d08a05f27904b4faca
1 change: 1 addition & 0 deletions src/Microsoft.OpenApi/Services/OpenApiFilterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static class OpenApiFilterService
var openApiOperations = GetOpenApiOperations(rootNode, url, apiVersion);
if (openApiOperations == null)
{
Console.WriteLine($"The url {url} could not be found in the OpenApi description");
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<None Update="UtilityFiles\postmanCollection_ver3.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\postmanCollection_ver4.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\Todo.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
22 changes: 22 additions & 0 deletions test/Microsoft.OpenApi.Tests/Services/OpenApiFilterServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ public void ThrowsExceptionWhenUrlsInCollectionAreMissingFromSourceDocument()
Assert.Equal("The urls in the Postman collection supplied could not be found.", message);
}

[Fact]
public void ContinueProcessingWhenUrlsInCollectionAreMissingFromSourceDocument()
{
// Arrange
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UtilityFiles\\postmanCollection_ver4.json");
var fileInput = new FileInfo(filePath);
var stream = fileInput.OpenRead();

// Act
var requestUrls = OpenApiService.ParseJsonCollectionFile(stream, _logger);
var pathCount = requestUrls.Count;
var predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: _openApiDocumentMock);
var subsetOpenApiDocument = OpenApiFilterService.CreateFilteredDocument(_openApiDocumentMock, predicate);
var subsetPathCount = subsetOpenApiDocument.Paths.Count;

// Assert
Assert.NotNull(subsetOpenApiDocument);
Assert.NotEmpty(subsetOpenApiDocument.Paths);
Assert.Equal(2, subsetPathCount);
Assert.NotEqual(pathCount, subsetPathCount);
}

[Fact]
public void ThrowsInvalidOperationExceptionInCreatePredicateWhenInvalidArgumentsArePassed()
{
Expand Down
145 changes: 145 additions & 0 deletions test/Microsoft.OpenApi.Tests/UtilityFiles/postmanCollection_ver4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"info": {
"_postman_id": "43402ca3-f018-7c9b-2315-f176d9b171a3",
"name": "Graph-Collection",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "users-GET",
"request": {
"method": "GET",
"url": {
"raw": "https://graph.microsoft.com/v1.0/users",
"protocol": "https",
"host": [
"graph",
"microsoft",
"com"
],
"path": [
"v1.0",
"users"
]
}
}
},
{
"name": "users-POST",
"request": {
"method": "POST",
"url": {
"raw": "https://graph.microsoft.com/v1.0/users",
"protocol": "https",
"host": [
"graph",
"microsoft",
"com"
],
"path": [
"v1.0",
"users"
]
}
}
},
{
"name": "/appCatalogs",
"request": {
"method": "GET",
"url": {
"raw": "https://graph.microsoft.com/v1.0/appCatalogs",
"protocol": "https",
"host": [
"graph",
"microsoft",
"com"
],
"path": [
"v1.0",
"appCatalogs"
]
}
}
},
{
"name": "/agreementAcceptances",
"request": {
"method": "GET",
"url": {
"raw": "https://graph.microsoft.com/v1.0/agreementAcceptances",
"protocol": "https",
"host": [
"graph",
"microsoft",
"com"
],
"path": [
"v1.0",
"agreementAcceptances"
]
}
}
},
{
"name": "{user-id}-GET",
"request": {
"method": "GET",
"url": {
"raw": "https://graph.microsoft.com/v1.0/users/{user-id}",
"protocol": "https",
"host": [
"graph",
"microsoft",
"com"
],
"path": [
"v1.0",
"users",
"{user-id}"
]
}
}
},
{
"name": "{user-id}-PATCH",
"request": {
"method": "PATCH",
"url": {
"raw": "https://graph.microsoft.com/v1.0/users/{user-id}",
"protocol": "https",
"host": [
"graph",
"microsoft",
"com"
],
"path": [
"v1.0",
"users",
"{user-id}"
]
}
}
},
{
"name": "{user-id}-DELETE",
"request": {
"method": "DELETE",
"url": {
"raw": "https://graph.microsoft.com/v1.0/users/{user-id}",
"protocol": "https",
"host": [
"graph",
"microsoft",
"com"
],
"path": [
"v1.0",
"users",
"{user-id}"
]
}
}
}
]
}