Skip to content

Commit

Permalink
Add test, fix implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
satano committed Jul 9, 2024
1 parent 309dec2 commit 6ba0f74
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,16 @@ private async Task<Uri> GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio
throw new InvalidOperationException(GetErrorMessage(endPoint));
}

var builder = new UriBuilder(GetScheme(service, route), service.DownstreamHost, service.DownstreamPort)
{
Path = endPoint.Service.Path
};
if (builder.Path.IsNullOrEmpty())
var builder = new UriBuilder(GetScheme(service, route), service.DownstreamHost, service.DownstreamPort);
if (endPoint.Service.Path.IsNullOrEmpty())
{
string version = endPoint.Version.IsNullOrEmpty() ? "v1" : endPoint.Version;
builder.Path = $"/swagger/{version}/swagger.json";
};
}
else
{
builder.Path = endPoint.Service.Path;
}

return builder.Uri;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ public async Task ReturnUriFromServiceDiscovery()
uri.AbsoluteUri.Should().Be("http://localhost:5000/swagger/v1/json");
}

[Fact]
public async Task RespectApiVersionWhenUriIsNotExplicitlySet()
{
SwaggerServiceDiscoveryProvider provider = CreateProvider(CreateService("Projects", "localhost", 5000));

Uri uri = await provider.GetSwaggerUriAsync(
new SwaggerEndPointConfig()
{
Version = "1.0",
Service = new SwaggerService() { Name = "Projects" }
},
new Configuration.RouteOptions());

uri.AbsoluteUri.Should().Be("http://localhost:5000/swagger/1.0/swagger.json");
}

[Fact]
public async Task ReturnUriFromServiceDiscoveryWhenRouteDoesntExist()
{
Expand Down

0 comments on commit 6ba0f74

Please sign in to comment.