Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update GetScheme method in SwaggerServiceDiscoveryProvider #310

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -28,7 +30,7 @@
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IOptions<SwaggerOptions> _swaggerOptions;

public SwaggerServiceDiscoveryProvider(

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

View workflow job for this annotation

GitHub Actions / build-and-test

Missing XML comment for publicly visible type or member 'SwaggerServiceDiscoveryProvider.SwaggerServiceDiscoveryProvider(IServiceDiscoveryProviderFactory, IServiceProviderConfigurationCreator, IOptionsMonitor<FileConfiguration>, IHttpContextAccessor, IOptions<SwaggerOptions>)'
IServiceDiscoveryProviderFactory serviceDiscovery,
IServiceProviderConfigurationCreator configurationCreator,
IOptionsMonitor<FileConfiguration> options,
Expand Down Expand Up @@ -106,11 +108,8 @@
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 @@
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,10 +134,10 @@
{
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 / build-and-test

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 / build-and-test

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

private static string GetErrorMessage(SwaggerEndPointConfig endPoint) =>
$"Service with swagger documentation '{endPoint.Service.Name}' cann't be discovered";
Expand Down
Loading