Skip to content

Commit

Permalink
Fix: Update GetScheme method in SwaggerServiceDiscoveryProvider (#310)
Browse files Browse the repository at this point in the history
* Updated GetScheme method in SwaggerServiceDiscoveryProvider

* Updated

---------

Co-authored-by: rabdulatif <latifrasulov10@gmailcom>
  • Loading branch information
rabdulatif and rabdulatif authored Oct 4, 2024
1 parent 8a25f0c commit aa5d3c7
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using MMLib.SwaggerForOcelot.Configuration;
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
using Ocelot.Configuration.Creator;
using Ocelot.Configuration.File;
Expand All @@ -13,6 +14,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using RouteOptions = MMLib.SwaggerForOcelot.Configuration.RouteOptions;

namespace MMLib.SwaggerForOcelot.ServiceDiscovery
{
Expand Down Expand Up @@ -106,11 +108,8 @@ private async Task<Uri> GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio
throw new InvalidOperationException(GetErrorMessage(endPoint));
}

var builder = new UriBuilder(GetScheme(service, route), service.DownstreamHost, service.DownstreamPort);
if (builder.Scheme.IsNullOrEmpty())
{
builder.Scheme = conf?.Scheme ?? "http";
}
var builder = new UriBuilder(GetScheme(service, route, conf), service.DownstreamHost,
service.DownstreamPort);

if (endPoint.Service.Path.IsNullOrEmpty())
{
Expand All @@ -125,7 +124,7 @@ private async Task<Uri> GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio
return builder.Uri;
}

private string GetScheme(ServiceHostAndPort service, RouteOptions route)
private string GetScheme(ServiceHostAndPort service, RouteOptions route, ServiceProviderConfiguration conf)
=> (route is not null && !route.DownstreamScheme.IsNullOrEmpty())
? route.DownstreamScheme
: !service.Scheme.IsNullOrEmpty()
Expand All @@ -135,7 +134,7 @@ private string GetScheme(ServiceHostAndPort service, RouteOptions route)
{
443 => Uri.UriSchemeHttps,
80 => Uri.UriSchemeHttp,
_ => string.Empty,
_ => conf?.Scheme ?? "http"
};

public static string? ServiceProviderType { get; set; }

Check warning on line 140 in src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs

View workflow job for this annotation

GitHub Actions / deploy

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 140 in src/MMLib.SwaggerForOcelot/ServiceDiscovery/SwaggerServiceDiscoveryProvider.cs

View workflow job for this annotation

GitHub Actions / deploy

Missing XML comment for publicly visible type or member 'SwaggerServiceDiscoveryProvider.ServiceProviderType'
Expand Down

0 comments on commit aa5d3c7

Please sign in to comment.