diff --git a/src/MMLib.SwaggerForOcelot/Middleware/SwaggerForOcelotMiddleware.cs b/src/MMLib.SwaggerForOcelot/Middleware/SwaggerForOcelotMiddleware.cs index b5d99d1..d15c279 100644 --- a/src/MMLib.SwaggerForOcelot/Middleware/SwaggerForOcelotMiddleware.cs +++ b/src/MMLib.SwaggerForOcelot/Middleware/SwaggerForOcelotMiddleware.cs @@ -69,7 +69,8 @@ public async Task Invoke(HttpContext context, ISwaggerEndPointProvider swaggerEndPointRepository, IDownstreamSwaggerDocsRepository downstreamSwaggerDocs) { - (string version, SwaggerEndPointOptions endPoint) = GetEndPoint(context.Request.Path, swaggerEndPointRepository); + (string version, SwaggerEndPointOptions endPoint) = + GetEndPoint(context.Request.Path, swaggerEndPointRepository); if (_downstreamInterceptor is not null && !_downstreamInterceptor.DoDownstreamSwaggerEndpoint(context, version, endPoint)) @@ -92,7 +93,8 @@ public async Task Invoke(HttpContext context, RouteOptions route = routeOptions.FirstOrDefault(r => r.SwaggerKey == endPoint.Key); string content = await downstreamSwaggerDocs.GetSwaggerJsonAsync(route, endPoint, version); - if (SwaggerServiceDiscoveryProvider.ServiceProviderType != "Consul") + if (SwaggerServiceDiscoveryProvider.ServiceProviderType != "Consul" && + SwaggerServiceDiscoveryProvider.ServiceProviderType != "PollConsul") { if (endPoint.TransformByOcelotConfig) { @@ -125,7 +127,7 @@ private string GetServerName(HttpContext context, SwaggerEndPointOptions endPoin if (string.IsNullOrWhiteSpace(_options.ServerOcelot)) { serverName = endPoint.HostOverride - ?? $"{context.Request.Scheme}://{context.Request.Host.Value.RemoveSlashFromEnd()}"; + ?? $"{context.Request.Scheme}://{context.Request.Host.Value.RemoveSlashFromEnd()}"; } else { @@ -137,7 +139,8 @@ private string GetServerName(HttpContext context, SwaggerEndPointOptions endPoin private async Task ReconfigureUpstreamSwagger(HttpContext context, string swaggerJson) { - if (_options.ReConfigureUpstreamSwaggerJson is not null && _options.ReConfigureUpstreamSwaggerJsonAsync is not null) + if (_options.ReConfigureUpstreamSwaggerJson is not null && + _options.ReConfigureUpstreamSwaggerJsonAsync is not null) { throw new Exception( "Both ReConfigureUpstreamSwaggerJson and ReConfigureUpstreamSwaggerJsonAsync cannot have a value. Only use one method."); diff --git a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs index 2cc8b7e..2769c73 100644 --- a/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs +++ b/src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs @@ -107,6 +107,12 @@ private async Task GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio } var builder = new UriBuilder(GetScheme(service, route), service.DownstreamHost, service.DownstreamPort); + if (builder.Scheme.IsNullOrEmpty()) + { + builder.Scheme = conf?.Scheme ?? "http"; + } + builder.Scheme = conf?.Scheme ?? "http"; + if (endPoint.Service.Path.IsNullOrEmpty()) { string version = endPoint.Version.IsNullOrEmpty() ? "v1" : endPoint.Version; @@ -122,19 +128,20 @@ private async Task GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio private string GetScheme(ServiceHostAndPort service, RouteOptions route) => (route is not null && !route.DownstreamScheme.IsNullOrEmpty()) - ? route.DownstreamScheme - : !service.Scheme.IsNullOrEmpty() - ? service.Scheme - : service.DownstreamPort - switch - { - 443 => Uri.UriSchemeHttps, - 80 => Uri.UriSchemeHttp, - _ => string.Empty, - }; + ? route.DownstreamScheme + : !service.Scheme.IsNullOrEmpty() + ? service.Scheme + : service.DownstreamPort + switch + { + 443 => Uri.UriSchemeHttps, + 80 => Uri.UriSchemeHttp, + _ => 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"; + private static string GetErrorMessage(SwaggerEndPointConfig endPoint) => + $"Service with swagger documentation '{endPoint.Service.Name}' cann't be discovered"; } }