feat: respect naming conventions across query, form and JSON body - #2154
Merged
Conversation
…mbly - Resolve all RoslynCommonAnalyzers/Sonar findings across runtime, the source generator, and tests with real fixes (no suppressions): collapse branches to conditionals, prefer &&/||/?? over ?: where a side is a literal, use switch expressions for #if 3-way returns, target-typed new, u8 literals, range/index, inlined out vars, and qualified-name shortening. - Move every Newtonsoft.Json-specific test out of Refit.Tests into a new Refit.Newtonsoft.Json.Tests project; Refit.Tests no longer references Refit.Newtonsoft.Json. Shared, non-serializer framework files are linked via Compile/Link; Newtonsoft-only helpers are relocated. Dual-serializer models are split into STJ and Newtonsoft variants. - Replace by-name-serialized anonymous payloads with named record types to satisfy SST2224 while preserving serialization semantics; keep the anonymous-type test anonymous with a single justified suppression. Full solution builds clean; all test projects pass.
- Add SnakeCaseUrlParameterKeyFormatter and KebabCaseUrlParameterKeyFormatter (camelCase already existed), backed by a shared TFM-portable converter - Add RefitSettings.CamelCase()/SnakeCase()/KebabCase() presets that configure query keys, form-url-encoded keys, and JSON body property names consistently - Route FormValueMultimap's property-name fallback through UrlParameterKeyFormatter so form keys honor the configured formatter; the default formatter is identity, so existing behavior is unchanged Addresses #1481 via opt-in presets rather than a breaking default change.
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2154 +/- ##
==========================================
- Coverage 97.63% 97.54% -0.09%
==========================================
Files 110 114 +4
Lines 5292 5305 +13
Branches 959 959
==========================================
+ Hits 5167 5175 +8
- Misses 28 33 +5
Partials 97 97 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisPulman
approved these changes
Jun 22, 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 + bug fix (closes #1481).
What is the new behavior?
First-class, opt-in support for choosing a naming convention that is applied consistently across query keys, form-url-encoded keys, and JSON body property names:
New
IUrlParameterKeyFormatterimplementations:SnakeCaseUrlParameterKeyFormatter(my_property) andKebabCaseUrlParameterKeyFormatter(my-property).CamelCaseUrlParameterKeyFormatteralready existed.New
RefitSettingspresets —RefitSettings.CamelCase(),RefitSettings.SnakeCase(),RefitSettings.KebabCase()— each wires up the matching URL key formatter and a matchingJsonNamingPolicy, so query, form, and body all agree:FormValueMultimapnow resolves a property's fallback name throughUrlParameterKeyFormatter(precedence unchanged:[AliasAs]->[JsonPropertyName]-> formatter), so form-url-encoded keys honour the configured formatter — the gap behind [Bug]: SystemTextJsonContentSerializer.GetFieldNameForProperty(PropertyInfo) does not use the provided JsonSerializerOptions #1481.The snake/kebab converters and naming policy are TFM-portable (they do not rely on the .NET 8+ built-in policies) and handle acronyms/digits (e.g.
JSONParser->json_parser).What is the current behavior?
Closes #1481.
What might this PR break?
None. The default
UrlParameterKeyFormatteris the identity formatter, so existing form/query behaviour is unchanged. The new behaviour is fully opt-in via a non-default formatter or a preset.Checklist
mainbranchAdditional information