-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug Fix #65 - If one path was substring another one, then transfromat… (
#66) * Bug Fix #65 - If one path was substring another one, then transfromation removed same methods. * Codefactor fix
- Loading branch information
Showing
10 changed files
with
1,381 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("MMLib.SwaggerForOcelot.Tests")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using MMLib.SwaggerForOcelot.Configuration; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace MMLib.SwaggerForOcelot | ||
{ | ||
/// <summary> | ||
/// Extensions for <see cref="ReRouteOptions"/>. | ||
/// </summary> | ||
internal static class ReRouteOptionsExtensions | ||
{ | ||
/// <summary> | ||
/// Goups the re routes by paths. | ||
/// </summary> | ||
/// <param name="reRouteOptions">The re route options.</param> | ||
public static IEnumerable<ReRouteOptions> GroupByPaths(this IEnumerable<ReRouteOptions> reRouteOptions) | ||
=> reRouteOptions | ||
.GroupBy(p => new { p.SwaggerKey, p.UpstreamPathTemplate, p.DownstreamPathTemplate, p.VirtualDirectory}) | ||
.Select(p => { | ||
var route = p.First(); | ||
return new ReRouteOptions( | ||
p.Key.SwaggerKey, | ||
route.UpstreamPathTemplate, | ||
route.DownstreamPathTemplate, | ||
p.Key.VirtualDirectory, | ||
p.Where(r => r.UpstreamHttpMethod != null).SelectMany(r => r.UpstreamHttpMethod)); | ||
}); | ||
|
||
/// <summary> | ||
/// Expands versions from one endpoint to more ReRoute options. | ||
/// </summary> | ||
/// <param name="reRoutes">The re routes.</param> | ||
/// <param name="endPoint">The end point.</param> | ||
public static IEnumerable<ReRouteOptions> ExpandConfig( | ||
this IEnumerable<ReRouteOptions> reRoutes, | ||
SwaggerEndPointOptions endPoint) | ||
{ | ||
var reRouteOptions = reRoutes.Where(p => p.SwaggerKey == endPoint.Key).ToList(); | ||
|
||
if (string.IsNullOrWhiteSpace(endPoint.VersionPlaceholder)) | ||
return reRouteOptions; | ||
|
||
var versionReRouteOptions = reRouteOptions.Where(x => | ||
x.DownstreamPathTemplate.Contains(endPoint.VersionPlaceholder) | ||
|| x.UpstreamPathTemplate.Contains(endPoint.VersionPlaceholder)).ToList(); | ||
versionReRouteOptions.ForEach(o => reRouteOptions.Remove(o)); | ||
foreach (var reRouteOption in versionReRouteOptions) | ||
{ | ||
var versionMappedReRouteOptions = endPoint.Config.Select(c => new ReRouteOptions() | ||
{ | ||
SwaggerKey = reRouteOption.SwaggerKey, | ||
DownstreamPathTemplate = | ||
reRouteOption.DownstreamPathTemplate.Replace(endPoint.VersionPlaceholder, | ||
c.Version), | ||
UpstreamHttpMethod = reRouteOption.UpstreamHttpMethod, | ||
UpstreamPathTemplate = | ||
reRouteOption.UpstreamPathTemplate.Replace(endPoint.VersionPlaceholder, | ||
c.Version), | ||
VirtualDirectory = reRouteOption.VirtualDirectory | ||
}); | ||
reRouteOptions.AddRange(versionMappedReRouteOptions); | ||
} | ||
|
||
return reRouteOptions; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/MMLib.SwaggerForOcelot.Tests/ReRouteOptionsExtensionsShould.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using FluentAssertions; | ||
using MMLib.SwaggerForOcelot.Configuration; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace MMLib.SwaggerForOcelot.Tests | ||
{ | ||
public class ReRouteOptionsExtensionsShould | ||
{ | ||
[Fact] | ||
public void GroupReRoutesByPaths() | ||
{ | ||
IEnumerable<ReRouteOptions> reRouteOptions = new List<ReRouteOptions>() | ||
{ | ||
new ReRouteOptions(){ | ||
DownstreamPathTemplate= "/api/masterdatatype", | ||
UpstreamPathTemplate = "/masterdatatype", | ||
UpstreamHttpMethod = new HashSet<string>(){ "Get"} | ||
}, | ||
new ReRouteOptions(){ | ||
DownstreamPathTemplate= "/api/masterdatatype", | ||
UpstreamPathTemplate = "/masterdatatype", | ||
UpstreamHttpMethod = new HashSet<string>(){ "Post"} | ||
}, | ||
new ReRouteOptions(){ | ||
DownstreamPathTemplate= "/api/masterdatatype/{everything}", | ||
UpstreamPathTemplate = "/masterdatatype/{everything}", | ||
UpstreamHttpMethod = new HashSet<string>(){ "Delete"} | ||
}, | ||
new ReRouteOptions(){ | ||
DownstreamPathTemplate= "/api/masterdatatype/{everything}", | ||
UpstreamPathTemplate = "/masterdatatype/{everything}", | ||
UpstreamHttpMethod = new HashSet<string>(){ "Delete"}, | ||
VirtualDirectory = "something" | ||
}, | ||
new ReRouteOptions(){ | ||
DownstreamPathTemplate= "/api/masterdata", | ||
UpstreamPathTemplate = "/masterdata", | ||
UpstreamHttpMethod = new HashSet<string>(){ "Delete"} | ||
}, | ||
}; | ||
|
||
IEnumerable<ReRouteOptions> actual = reRouteOptions.GroupByPaths(); | ||
|
||
actual | ||
.Should() | ||
.HaveCount(4); | ||
|
||
actual.First() | ||
.UpstreamHttpMethod | ||
.Should() | ||
.BeEquivalentTo("Get", "Post"); | ||
} | ||
} | ||
} |
Oops, something went wrong.
dc31a7f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting this issue in this version.
https://stackoverflow.com/questions/59772540/request-url-error-in-swagger-for-ocelot-like-http-http
Can you please investigate it?
dc31a7f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, it looks like issue #53
Unfortunately it is still not fixed.
As a workaround you can downgrade to version
1.8
Thank you and apologize.