Skip to content

Commit

Permalink
Merge branch 'rabdulatif-ocelot_pollConsul'
Browse files Browse the repository at this point in the history
  • Loading branch information
Burgyn committed Oct 4, 2024
2 parents 3066153 + 2e8a662 commit 8a25f0c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/MMLib.SwaggerForOcelot/MMLib.SwaggerForOcelot.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Version>8.3.0</Version>
<Version>8.3.1</Version>
<Authors>Milan Martiniak</Authors>
<Company>MMLib</Company>
<Description>Swagger generator for Ocelot downstream services.</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
{
Expand All @@ -137,7 +139,8 @@ private string GetServerName(HttpContext context, SwaggerEndPointOptions endPoin

private async Task<string> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ private async Task<Uri> GetSwaggerUri(SwaggerEndPointConfig endPoint, RouteOptio
}

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

if (endPoint.Service.Path.IsNullOrEmpty())
{
string version = endPoint.Version.IsNullOrEmpty() ? "v1" : endPoint.Version;
Expand All @@ -122,19 +127,20 @@ private async Task<Uri> 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; }

Check warning on line 141 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 141 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'

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";
}
}

0 comments on commit 8a25f0c

Please sign in to comment.