diff --git a/src/Tochka.JsonRpc.OpenRpc/Services/OpenRpcDocumentGenerator.cs b/src/Tochka.JsonRpc.OpenRpc/Services/OpenRpcDocumentGenerator.cs index 275c095..e3961d5 100644 --- a/src/Tochka.JsonRpc.OpenRpc/Services/OpenRpcDocumentGenerator.cs +++ b/src/Tochka.JsonRpc.OpenRpc/Services/OpenRpcDocumentGenerator.cs @@ -76,7 +76,7 @@ internal virtual List GetServers(Uri host) var controllerSummary = actionDescriptor?.ControllerTypeInfo.GetXmlDocsSummary(); var route = apiDescription.RelativePath?.Split('#').First(); - if (string.IsNullOrWhiteSpace(route) || $"/{route}" == serverOptions.RoutePrefix) + if (string.IsNullOrWhiteSpace(route) || $"/{route}" == serverOptions.RoutePrefix || servers.Any(x => x.Url.AbsolutePath.Contains(route, StringComparison.OrdinalIgnoreCase))) { continue; } diff --git a/src/tests/Tochka.JsonRpc.OpenRpc.Tests/Services/OpenRpcDocumentGeneratorTests.cs b/src/tests/Tochka.JsonRpc.OpenRpc.Tests/Services/OpenRpcDocumentGeneratorTests.cs index c621f0c..1a42d7d 100644 --- a/src/tests/Tochka.JsonRpc.OpenRpc.Tests/Services/OpenRpcDocumentGeneratorTests.cs +++ b/src/tests/Tochka.JsonRpc.OpenRpc.Tests/Services/OpenRpcDocumentGeneratorTests.cs @@ -136,10 +136,11 @@ public void GetServersReturnsAllEndpoints() { var apiDescription1 = GetValidDescription(); var apiDescription2 = GetValidDescription(); - var path = "default/path"; + var firstPath = "first/path"; + var secondPath = "second/path"; serverOptions.RoutePrefix = "/"; - apiDescription1.RelativePath = $"{path}#{MethodName}"; - apiDescription2.RelativePath = $"{path}#{MethodName}"; + apiDescription1.RelativePath = $"{firstPath}#{MethodName}"; + apiDescription2.RelativePath = $"{secondPath}#{MethodName}"; apiDescriptionsProviderMock.Setup(static p => p.ApiDescriptionGroups) .Returns(new ApiDescriptionGroupCollection(new List @@ -157,6 +158,32 @@ public void GetServersReturnsAllEndpoints() result.Should().HaveCount(2); } + [Test] + public void GetServersSameRouteReturnsOnlyOne() + { + var apiDescription1 = GetValidDescription(); + var apiDescription2 = GetValidDescription(); + var samePath = "default/path"; + serverOptions.RoutePrefix = "/"; + apiDescription1.RelativePath = $"{samePath}#{MethodName}"; + apiDescription2.RelativePath = $"{samePath}#{MethodName}"; + + apiDescriptionsProviderMock.Setup(static p => p.ApiDescriptionGroups) + .Returns(new ApiDescriptionGroupCollection(new List + { + new(null, new[] { apiDescription1 }), + new(null, new[] { apiDescription2 }), + }, + 0)) + .Verifiable(); + + var result = documentGeneratorMock.Object.GetServers(new Uri(Host)); + + apiDescriptionsProviderMock.Verify(); + documentGeneratorMock.Verify(); + result.Should().HaveCount(1); + } + [Test] public void GetServersPathAndRoutePrefixSameReturnsEmptyServers() {