diff --git a/src/MMLib.SwaggerForOcelot/Middleware/SwaggerForOcelotMiddleware.cs b/src/MMLib.SwaggerForOcelot/Middleware/SwaggerForOcelotMiddleware.cs index 544c8b9..4e4fa5d 100644 --- a/src/MMLib.SwaggerForOcelot/Middleware/SwaggerForOcelotMiddleware.cs +++ b/src/MMLib.SwaggerForOcelot/Middleware/SwaggerForOcelotMiddleware.cs @@ -1,4 +1,4 @@ -using Kros.Utils; +using Kros.Utils; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; using MMLib.SwaggerForOcelot.Configuration; @@ -14,6 +14,7 @@ using Microsoft.OpenApi.Writers; using System.Text; using Microsoft.OpenApi.Models; +using MMLib.SwaggerForOcelot.ServiceDiscovery; namespace MMLib.SwaggerForOcelot.Middleware { @@ -91,15 +92,14 @@ public async Task Invoke(HttpContext context, RouteOptions route = routeOptions.FirstOrDefault(r => r.SwaggerKey == endPoint.Key); string content = await downstreamSwaggerDocs.GetSwaggerJsonAsync(route, endPoint, version); - - if (endPoint.TransformByOcelotConfig) + if (SwaggerServiceDiscoveryProvider.ServiceProviderType != "Consul") { - content = _transformer.Transform( - content, - routeOptions, - GetServerName(context, endPoint), - endPoint); + if (endPoint.TransformByOcelotConfig) + { + content = _transformer.Transform(content, routeOptions, GetServerName(context, endPoint), endPoint); + } } + content = await ReconfigureUpstreamSwagger(context, content); await context.Response.WriteAsync(content); diff --git a/src/MMLib.SwaggerForOcelot/Repositories/DownstreamSwaggerDocsRepository.cs b/src/MMLib.SwaggerForOcelot/Repositories/DownstreamSwaggerDocsRepository.cs index 2c9615b..a597746 100644 --- a/src/MMLib.SwaggerForOcelot/Repositories/DownstreamSwaggerDocsRepository.cs +++ b/src/MMLib.SwaggerForOcelot/Repositories/DownstreamSwaggerDocsRepository.cs @@ -46,6 +46,11 @@ public async Task GetSwaggerJsonAsync( var clientName = _options.Value.HttpClientName ?? ((route?.DangerousAcceptAnyServerCertificateValidator ?? false) ? ServiceCollectionExtensions.IgnoreSslCertificate : string.Empty); var httpClient = _httpClientFactory.CreateClient(clientName); + if (!(url.StartsWith("http://",StringComparison.InvariantCultureIgnoreCase) || url.StartsWith("https://",StringComparison.InvariantCultureIgnoreCase))) + { + url = "https://" + url; + } + SetHttpVersion(httpClient, route); AddHeaders(httpClient); diff --git a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs index bab1ea6..bd5b7a3 100644 --- a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs +++ b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs @@ -81,6 +81,8 @@ private async Task GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio { var conf = _configurationCreator.Create(_options.CurrentValue.GlobalConfiguration); + ServiceProviderType = conf?.Type; + var downstreamRoute = new DownstreamRouteBuilder() .WithUseServiceDiscovery(true) .WithServiceName(endPoint.Service.Name) @@ -125,6 +127,8 @@ private string GetScheme(ServiceHostAndPort service, RouteOptions route) _ => string.Empty, }; + public static string? ServiceProviderType { get; set; } + private static string GetErrorMessage(SwaggerEndPointConfig endPoint) => $"Service with swagger documentation '{endPoint.Service.Name}' cann't be discovered"; } }