-
Notifications
You must be signed in to change notification settings - Fork 279
Support trailing slashes in paths #1584
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -150,6 +150,13 @@ public OpenApiUrlTreeNode Attach(string path, | |||||
| } | ||||||
|
|
||||||
| var segments = path.Split('/'); | ||||||
| if (path.EndsWith("/", StringComparison.OrdinalIgnoreCase)) | ||||||
| { | ||||||
| // Remove the last element, which is empty, and append the trailing slash to the new last element | ||||||
| // This is to support URLs with trailing slashes | ||||||
| Array.Resize(ref segments, segments.Length - 1); | ||||||
| segments[segments.Length - 1] += "/"; | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| return Attach(segments: segments, | ||||||
| pathItem: pathItem, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -466,5 +466,38 @@ public async Task VerifyDiagramFromSampleOpenAPI() | |||||||||
|
|
||||||||||
| await Verifier.Verify(diagram); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public static TheoryData<string, string[], string, string> SupportsTrailingSlashesInPathData => new TheoryData<string, string[], string, string> | ||||||||||
| { | ||||||||||
| // Path, children up to second to leaf, last expected leaf node name, expected leaf node path | ||||||||||
| { "/cars/{car-id}/build/", ["cars", "{car-id}"], "build/", @"\cars\{car-id}\build/" }, | ||||||||||
| { "/cars/", [], "cars/", @"\cars/" }, | ||||||||||
|
Comment on lines
+473
to
+474
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
wouldn't this make more sense?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's for you to say. My interpretation was that If you want the changes in, though, that's fine, I'll push them.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as long as it doesn't derail the logic/node structure, it'd make sense to be consistent.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't find out why we used backslash as a separator. It doesn't make sense to me. I tried looking at all the relevant PRs. Maybe @irvinesunday remembers?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't used backslash anywhere as a separator within this codebase 🤔
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alright, thanks for your patience with us @mderriey it seems we suffer from collective amnesia. |
||||||||||
| }; | ||||||||||
|
|
||||||||||
| [Theory] | ||||||||||
| [MemberData(nameof(SupportsTrailingSlashesInPathData))] | ||||||||||
| public void SupportsTrailingSlashesInPath(string path, string[] childrenBeforeLastNode, string expectedLeafNodeName, string expectedLeafNodePath) | ||||||||||
| { | ||||||||||
| var openApiDocument = new OpenApiDocument | ||||||||||
| { | ||||||||||
| Paths = new() | ||||||||||
| { | ||||||||||
| [path] = new() | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| var label = "trailing-slash"; | ||||||||||
| var rootNode = OpenApiUrlTreeNode.Create(openApiDocument, label); | ||||||||||
|
|
||||||||||
| var secondToLeafNode = rootNode; | ||||||||||
| foreach (var childName in childrenBeforeLastNode) | ||||||||||
| { | ||||||||||
| secondToLeafNode = secondToLeafNode.Children[childName]; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| Assert.True(secondToLeafNode.Children.TryGetValue(expectedLeafNodeName, out var leafNode)); | ||||||||||
| Assert.Equal(expectedLeafNodePath, leafNode.Path); | ||||||||||
| Assert.Empty(leafNode.Children); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
Uh oh!
There was an error while loading. Please reload this page.