Repository navigation
feat: add per-type URL parameter formatter registry - #2226
Merged
Merged
Conversation
- Add `RefitSettings.UrlParameterFormatterMap`, a `Type`-keyed `IUrlParameterFormatter` registry consulted before `UrlParameterFormatter` when rendering path and query values (exact runtime type, default fallback). - Centralize resolution in `GeneratedRequestRunner.FormatUrlParameter`, called by both the reflection request builder and the generated runtime helpers, so the two request paths stay in parity automatically. - Route path, round-trip segment, query, dictionary-key and collection formatting through the registry; a populated map opts a request out of the generator's inline formatting fast path. - Cover reflection, generated, parity and fallback behavior with tests; record the new public API and document the setting in the README and breaking-changes notes. Closes #2219
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2226 +/- ##
=======================================
Coverage 99.70% 99.70%
=======================================
Files 177 177
Lines 9259 9275 +16
Branches 1728 1729 +1
=======================================
+ Hits 9232 9248 +16
Misses 8 8
Partials 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
glennawatson
marked this pull request as ready for review
July 14, 2026 14:43
…ameter-formatter # Conflicts: # docs/breaking-changes.md
…ameter-formatter # Conflicts: # docs/breaking-changes.md
|
ChrisPulman
approved these changes
Jul 15, 2026
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What kind of change does this PR introduce?
Feature (additive, opt-in) - a per-type URL parameter formatter registry on
RefitSettings.What is the new behavior?
RefitSettings.UrlParameterFormatterMap- anIDictionary<Type, IUrlParameterFormatter>(empty by default) keyed by the CLR type it formats.{**param}segment, or query value), its runtime type (value.GetType()) is looked up in the map first. A registered formatter wins; every other type falls back to the existingUrlParameterFormatter.GeneratedRequestRunner.FormatUrlParameter) that BOTH request paths call, so the reflection request builder and the source-generated request builder produce identical URLs. AOT/trim-safe:value.GetType()only, no reflection over members.What is the current behavior?
Every path/query value is formatted through the single
RefitSettings.UrlParameterFormatter(falling back toToString()). To customize one specific type you must write a customIUrlParameterFormatterthat switches onvalue.GetType()for every call.Closes #2219
What might this PR break?
Nothing for existing code. The default map is empty, which changes no behavior -
FormatUrlParameterresolves to the configuredUrlParameterFormatterexactly as before. The only signature change is the internal generator-support helperGeneratedRequestRunner.RoundTripEscapePath(marked[EditorBrowsable(Never)], only called by generated code), which now takesRefitSettingsinstead ofIUrlParameterFormatter; generated output is regenerated to match.Checklist
mainbranchAdditional information
RefitSettings.UrlParameterFormatterMap,GeneratedRequestRunner.FormatUrlParameter); generator snapshots reviewed and updated (custom formatting branch now routes throughFormatUrlParameter).docs/breaking-changes.md.GeneratedRequestRunner(the existing hidden,[EditorBrowsable(Never)]shared runtime-helper class) so the visible public surface added toRefitSettingsis just the map. Registering a per-type formatter for the collection/round-trip cases applies per element/section by the element's runtime type, matching the reflection builder.