Skip to content

Commit

Permalink
Merge pull request #117 from SedativeEffect/feature/C-SHARP-196-all-e…
Browse files Browse the repository at this point in the history
…ndpoints

fix(autodoc): remove duplicate endpoints at servers section
  • Loading branch information
BigDaddy1337 authored Aug 27, 2024
2 parents a7e1827 + bc4bf16 commit 77b9d28
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal virtual List<OpenRpcServer> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApiDescriptionGroup>
Expand All @@ -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<ApiDescriptionGroup>
{
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()
{
Expand Down

0 comments on commit 77b9d28

Please sign in to comment.