From 309dec22c55eb9a09b0044b728c99c6f6449f943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stano=20Gabo=20Pe=C5=A5ko?= Date: Tue, 9 Jul 2024 10:08:38 +0200 Subject: [PATCH] Respect configured API version in downstream path --- .../ServiceDiscovery/SwaggerService.cs | 2 +- .../SwaggerServiceDiscoveryProvider.cs | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerService.cs b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerService.cs index 7120519..5487e3b 100644 --- a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerService.cs +++ b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerService.cs @@ -13,6 +13,6 @@ public class SwaggerService /// /// Gets or sets the path. /// - public string Path { get; set; } = "/swagger/v1/swagger.json"; + public string Path { get; set; } } } diff --git a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs index bd5b7a3..3029bfd 100644 --- a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs +++ b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs @@ -1,7 +1,4 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Kros.Extensions; +using Kros.Extensions; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using MMLib.SwaggerForOcelot.Configuration; @@ -13,6 +10,9 @@ using Ocelot.ServiceDiscovery.Providers; using Ocelot.Values; using Swashbuckle.AspNetCore.Swagger; +using System; +using System.Linq; +using System.Threading.Tasks; namespace MMLib.SwaggerForOcelot.ServiceDiscovery { @@ -110,6 +110,11 @@ private async Task GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio { Path = endPoint.Service.Path }; + if (builder.Path.IsNullOrEmpty()) + { + string version = endPoint.Version.IsNullOrEmpty() ? "v1" : endPoint.Version; + builder.Path = $"/swagger/{version}/swagger.json"; + }; return builder.Uri; }