diff --git a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs index 3029bfd..8c89179 100644 --- a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs +++ b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs @@ -106,15 +106,16 @@ private async Task 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; } diff --git a/tests/MMLib.SwaggerForOcelot.Tests/ServiceDiscovery/SwaggerServiceDiscoveryProviderShould.cs b/tests/MMLib.SwaggerForOcelot.Tests/ServiceDiscovery/SwaggerServiceDiscoveryProviderShould.cs index b91757c..1463a9e 100644 --- a/tests/MMLib.SwaggerForOcelot.Tests/ServiceDiscovery/SwaggerServiceDiscoveryProviderShould.cs +++ b/tests/MMLib.SwaggerForOcelot.Tests/ServiceDiscovery/SwaggerServiceDiscoveryProviderShould.cs @@ -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() {