|
1 |
| -// Copyright (c) Microsoft Corporation. All rights reserved. |
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
2 | 2 | // Licensed under the MIT license.
|
3 | 3 |
|
4 | 4 | using Microsoft.Extensions.Logging;
|
@@ -105,6 +105,57 @@ public void TestPredicateFiltersUsingRelativeRequestUrls()
|
105 | 105 | Assert.False(predicate("/foo", OperationType.Patch, null));
|
106 | 106 | }
|
107 | 107 |
|
| 108 | + [Fact] |
| 109 | + public void CreateFilteredDocumentUsingPredicateFromRequestUrl() |
| 110 | + { |
| 111 | + // Arrange |
| 112 | + var openApiDocument = new OpenApiDocument |
| 113 | + { |
| 114 | + Info = new() { Title = "Test", Version = "1.0" }, |
| 115 | + Servers = new List<OpenApiServer> { new() { Url = "https://localhost/" } }, |
| 116 | + Paths = new() |
| 117 | + { |
| 118 | + ["/test/{id}"] = new() |
| 119 | + { |
| 120 | + Operations = new Dictionary<OperationType, OpenApiOperation> |
| 121 | + { |
| 122 | + { OperationType.Get, new() }, |
| 123 | + { OperationType.Patch, new() } |
| 124 | + }, |
| 125 | + Parameters = new List<OpenApiParameter> |
| 126 | + { |
| 127 | + new() |
| 128 | + { |
| 129 | + Name = "id", |
| 130 | + In = ParameterLocation.Path, |
| 131 | + Required = true, |
| 132 | + Schema = new() |
| 133 | + { |
| 134 | + Type = "string" |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + |
| 141 | + } |
| 142 | + }; |
| 143 | + |
| 144 | + var requestUrls = new Dictionary<string, List<string>> |
| 145 | + { |
| 146 | + {"/test/{id}", new List<string> {"GET","PATCH"}} |
| 147 | + }; |
| 148 | + |
| 149 | + // Act |
| 150 | + var predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source: openApiDocument); |
| 151 | + var subsetDoc = OpenApiFilterService.CreateFilteredDocument(openApiDocument, predicate); |
| 152 | + |
| 153 | + // Assert that there's only 1 parameter in the subset document |
| 154 | + Assert.NotNull(subsetDoc); |
| 155 | + Assert.NotEmpty(subsetDoc.Paths); |
| 156 | + Assert.Single(subsetDoc.Paths.First().Value.Parameters); |
| 157 | + } |
| 158 | + |
108 | 159 | [Fact]
|
109 | 160 | public void ShouldParseNestedPostmanCollection()
|
110 | 161 | {
|
|
0 commit comments