feat: add generated request building support for path parameters in the URL.#2174
feat: add generated request building support for path parameters in the URL.#2174calebkiage wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Thanks for the draft. Know it's WIP - a few notes that should help when you pick it back up.
Runtime bug in GeneratedRequestRunner.BuildRequestPath:
var isPathParam = index > 0 && toReplace[index - 1] == '/';toReplace[index - 1] indexes the literal "{key}" instead of path; should be path[index - 1]. As written, /users/{user} throws IndexOutOfRangeException and /{id} leaves the placeholder unreplaced. One-char fix.
Test gap: the new tests only check generated text + CompilesWithoutErrors; nothing executes a path-param request. The one emit-load-invoke test uses [Get("/users")] (no param). An emit-load-invoke case asserting the final RequestUri (single, multiple, non-string, null/empty) would catch the bug above - most valuable addition here.
Smaller, for later:
- Empty value drops the whole segment (
/users/{user}->/users); reflection substitutes?? string.Empty->/users/. Worth aligning so inline and reflective URIs match. replacementBlockRegexadds a per-match alloc into the parse hot path stage 1 de-LINQ'd, and the camelCase static name likely trips the analyzers; a manual scan avoids both and drops the duplicate brace logic.- Confirm
params ReadOnlySpan<(string, string?)>(C# 13) compiles on the net4x TFMs - no CI ran on the branch.
Use scanning over regex matching in Parser.Request.cs. Support query parameters that are part of the path string.
# Conflicts: # src/Refit/PublicAPI/net10.0/PublicAPI.Unshipped.txt # src/Refit/PublicAPI/net11.0/PublicAPI.Unshipped.txt # src/Refit/PublicAPI/net462/PublicAPI.Unshipped.txt # src/Refit/PublicAPI/net470/PublicAPI.Unshipped.txt # src/Refit/PublicAPI/net471/PublicAPI.Unshipped.txt # src/Refit/PublicAPI/net472/PublicAPI.Unshipped.txt # src/Refit/PublicAPI/net48/PublicAPI.Unshipped.txt # src/Refit/PublicAPI/net481/PublicAPI.Unshipped.txt # src/Refit/PublicAPI/net8.0/PublicAPI.Unshipped.txt # src/Refit/PublicAPI/net9.0/PublicAPI.Unshipped.txt
|
@glennawatson, good catch on the bug. Was working on this late.
It looks like there are already tests that check for parameter substitution. They were failing and I've fixed most of them.
So if a path like How should generated code behave when |
Yep, agreed -- and I think that's the behavior we actually want. It matches what reflection already does (
This is the part I care more about -- it's a real parity gap vs reflection. Let's get the generated code calling into it: route each path value through |
…toryWithoutReflectionBuilder test
a2d898c to
11acde7
Compare
|
I have the first iteration of |
What kind of change does this PR introduce?
Adds generated request building support for path parameters provided in the URL.
What is the new behavior?
If a URL has path parameters defined in the URL and the method signature has parameters matching the path parameter, then the source generator will create a method that uses source generation.
The method signature below will now use a generated method body.
What is the current behavior?
The old behavior used reflection for any methods that have parameters in the path.
What might this PR break?
None
Checklist
mainbranchAdditional information