Skip to content

Commit 77b9d28

Browse files
authored
Merge pull request #117 from SedativeEffect/feature/C-SHARP-196-all-endpoints
fix(autodoc): remove duplicate endpoints at servers section
2 parents a7e1827 + bc4bf16 commit 77b9d28

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/Tochka.JsonRpc.OpenRpc/Services/OpenRpcDocumentGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ internal virtual List<OpenRpcServer> GetServers(Uri host)
7676
var controllerSummary = actionDescriptor?.ControllerTypeInfo.GetXmlDocsSummary();
7777
var route = apiDescription.RelativePath?.Split('#').First();
7878

79-
if (string.IsNullOrWhiteSpace(route) || $"/{route}" == serverOptions.RoutePrefix)
79+
if (string.IsNullOrWhiteSpace(route) || $"/{route}" == serverOptions.RoutePrefix || servers.Any(x => x.Url.AbsolutePath.Contains(route, StringComparison.OrdinalIgnoreCase)))
8080
{
8181
continue;
8282
}

src/tests/Tochka.JsonRpc.OpenRpc.Tests/Services/OpenRpcDocumentGeneratorTests.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ public void GetServersReturnsAllEndpoints()
136136
{
137137
var apiDescription1 = GetValidDescription();
138138
var apiDescription2 = GetValidDescription();
139-
var path = "default/path";
139+
var firstPath = "first/path";
140+
var secondPath = "second/path";
140141
serverOptions.RoutePrefix = "/";
141-
apiDescription1.RelativePath = $"{path}#{MethodName}";
142-
apiDescription2.RelativePath = $"{path}#{MethodName}";
142+
apiDescription1.RelativePath = $"{firstPath}#{MethodName}";
143+
apiDescription2.RelativePath = $"{secondPath}#{MethodName}";
143144

144145
apiDescriptionsProviderMock.Setup(static p => p.ApiDescriptionGroups)
145146
.Returns(new ApiDescriptionGroupCollection(new List<ApiDescriptionGroup>
@@ -157,6 +158,32 @@ public void GetServersReturnsAllEndpoints()
157158
result.Should().HaveCount(2);
158159
}
159160

161+
[Test]
162+
public void GetServersSameRouteReturnsOnlyOne()
163+
{
164+
var apiDescription1 = GetValidDescription();
165+
var apiDescription2 = GetValidDescription();
166+
var samePath = "default/path";
167+
serverOptions.RoutePrefix = "/";
168+
apiDescription1.RelativePath = $"{samePath}#{MethodName}";
169+
apiDescription2.RelativePath = $"{samePath}#{MethodName}";
170+
171+
apiDescriptionsProviderMock.Setup(static p => p.ApiDescriptionGroups)
172+
.Returns(new ApiDescriptionGroupCollection(new List<ApiDescriptionGroup>
173+
{
174+
new(null, new[] { apiDescription1 }),
175+
new(null, new[] { apiDescription2 }),
176+
},
177+
0))
178+
.Verifiable();
179+
180+
var result = documentGeneratorMock.Object.GetServers(new Uri(Host));
181+
182+
apiDescriptionsProviderMock.Verify();
183+
documentGeneratorMock.Verify();
184+
result.Should().HaveCount(1);
185+
}
186+
160187
[Test]
161188
public void GetServersPathAndRoutePrefixSameReturnsEmptyServers()
162189
{

0 commit comments

Comments
 (0)