-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
#2199 Adding support of placeholder matching between slashes👍 #2200
#2199 Adding support of placeholder matching between slashes👍 #2200
Conversation
…oduct/products/categories/ since the last slash is part of the template and not the catch-all placeholder
@raman-m yeaaaah, the checks have passed ;-) |
Gui, how quickly do you need this delivered? Do you require the officially released NuGet package, or can you wait for the next v24.0? |
Congratulations! 🎉 It appears that the old functionality remains intact. |
It's urgent, but, when it is foreseen to release v24.0? |
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.
My suggestions are below 👇
src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
Show resolved
Hide resolved
src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
Show resolved
Hide resolved
src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
Show resolved
Hide resolved
src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs
Show resolved
Hide resolved
...elot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs
Outdated
Show resolved
Hide resolved
@ggnaegi, I'm OK to release minor version 23.4.0 with the already merged 2 features + this feat. Will you prepare the release PR for urgent delivery? Will you write the release notes, etc.? Or will our next minor release be without release notes? 😄
First days, 1st week of December, I guess... |
Ok let's do this, minor version 23.4.0 |
OK! Your destiny, Gui, is to write the documentation for the feature. It seems we have to review all Routing documentation to inform the community that we support placeholders in the middle. |
@ggnaegi Are you going to write acceptance tests and update docs? |
...elot.UnitTests/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinderTests.cs
Show resolved
Hide resolved
Yes! |
…aceholderNameAndValueFinderTests.cs Recover old test for feat 89. Remove BDDfy from new unit tests. Apply AAA-pattern.
Yes, but the old unit test, is totally crap! I'm wondering why it should pass! It's stupid |
Do you think we had a stupid contributor in #89 ? 😄 |
this.Given(x => x.GivenIHaveAUpstreamPath("api/product/products/categories/"))
.And(x => x.GivenIHaveAnUpstreamUrlTemplate("api/{finalUrlPath}/")) // Gui, don't remove final slash! We should not break old functionality
.When(x => x.WhenIFindTheUrlVariableNamesAndValues())
.And(x => x.ThenTheTemplatesVariablesAre(expectedTemplates))
.BDDfy();
} Why on earth {finalUrlPath} should match /product/products/categories/ if the slash is not part of it????? Besides, the acceptance test is passing... |
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.
Sorry, I require the following missing artifacts from the development process:
- Acceptance test(s) with the same data as the new unit tests
- Updated documentation for the Routing feature, at least draft with ideas to review
P.S. Regarding the #89 failed test
I saw that the unit test fails, but the corresponding #89 acceptance test doesn't, which is strange. Logically, both tests should fail together or they should both pass. I recommend carefully reviewing the #89 and syncing the test data, at least for a final decision.
Upon reviewing the old #89 tests, I noticed that the author made a typo error in the unit test, specifically an extra The tests have been reviewed and are now successfully passing. Apologies for any inconvenience over the past two days! Ocelot/src/Ocelot/DownstreamRouteFinder/UrlMatcher/UrlPathPlaceholderNameAndValueFinder.cs Line 124 in da9d6fa
Trim(delimiter) . This is why the old typo and the corrected unit test coexist in the codebase. However, this does not align with the actual requirements of feature #89.
If you don't mind, I will refactor both files along with the tests to adhere to our development conventions. |
When? |
@raman-m 🤣 |
@raman-m ready |
FindGroups method is private, better to return exact type. Regex optimizations across net6, 7, 8. XML dev-docs markup review. Rename 'curly bracket' to 'brace'.
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.
Ready for Delivery ✅
Feel free to press the magic Squash button! 🎉
If you merge today, I will prepare the release v23.4.0 for tomorrow.
Embedded Placeholders [#f1]_ | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
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.
It's okay now. Thank you for writing this! I will review the section again during the release.
[Theory] | ||
[Trait("Bug", "2199")] | ||
[Trait("Feat", "2200")] | ||
[InlineData("/api/invoices/{url0}-{url1}-{url2}", "/api/invoices_{url0}/{url1}-{url2}_abcd/{url3}?urlId={url4}", | ||
"/api/invoices_abc/def-ghi_abcd/xyz?urlId=bla", "/api/invoices/abc-def-ghi", "?urlId=bla")] | ||
[InlineData("/api/products/{category}-{subcategory}/{filter}", "/api/products_{category}/{subcategory}_details/{itemId}?filter={filter}", | ||
"/api/products_electronics/computers_details/123?filter=active", "/api/products/electronics-computers/active", "")] | ||
[InlineData("/api/users/{userId}/posts/{postId}/{lang}", "/api/users/{userId}/{postId}_content/{timestamp}?lang={lang}", | ||
"/api/users/101/2022_content/2024?lang=en", "/api/users/101/posts/2022/en", "")] | ||
[InlineData("/api/categories/{cat}-{subcat}?sort={sort}", "/api/categories_{cat}/{subcat}_items/{itemId}?sort={sort}", | ||
"/api/categories_home/furniture_items/789?sort=asc", "/api/categories/home-furniture", "?sort=asc")] | ||
[InlineData("/api/orders/{order}-{detail}?status={status}", "/api/orders_{order}/{detail}_invoice/{ref}?status={status}", | ||
"/api/orders_987/abc_invoice/123?status=shipped", "/api/orders/987-abc", "?status=shipped")] | ||
[InlineData("/api/transactions/{type}-{region}", "/api/transactions_{type}/{region}_summary/{year}?q={query}", | ||
"/api/transactions_sales/NA_summary/2024?q=forecast", "/api/transactions/sales-NA", "?q=forecast")] | ||
[InlineData("/api/resources/{resource}-{subresource}", "/api/resources_{resource}/{subresource}_data/{id}?key={apikey}", | ||
"/api/resources_images/photos_data/555?key=xyz123", "/api/resources/images-photos", "?key=xyz123")] | ||
[InlineData("/api/accounts/{account}-{detail}", "/api/accounts_{account}/{detail}_info/{id}?opt={option}", | ||
"/api/accounts_admin/settings_info/101?opt=true", "/api/accounts/admin-settings", "?opt=true")] | ||
public void ShouldMatchComplexQueriesWithEmbeddedPlaceholders(string downstream, string upstream, string requestUrl, string downstreamPath, string queryString) |
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.
Thank you for adding these tests! I have a question.
Does the feat support embedded placeholders within a single query parameter and its value?
For example →
/api/invoices_{url0}/{url1}-{url2}_abcd/{url3}?Id1={id1}&filter=A{fid1}B&text=quick fox jumped over lazy {animal2} and&etc
I assume the answer is NO...
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.
@raman-m It should work yes, it focuses on the left and right brackets for the matching
Fixes #2199
Proposed Changes
Reworked
UrlPathPlaceholderNameAndValueFinder.cs
supporting now embedded placeholdersPattern matching with Regexes
Some tweaks:
Added some unit tests with complex path templates.
Added code comments