refit
refit copied to clipboard
Support CamelCase Query
Is your feature request related to a problem? Please describe.
I have a class like this
public class Query
{
public int? Limit { get; set; }
public int? Offset { get; set; }
}
It needs to be converted like this
?limit=10&offset=0
But it is actually converted to
?Limit=10&Offset=0
Is there any way to support CamelCase without using AliasAs?
Describe the solution you'd like
I am now like this but very redundant
public class Query
{
[AliasAs("limit")]
public int? Limit { get; set; }
[AliasAs("offset")]
public int? Offset { get; set; }
}
Describe alternatives you've considered
Describe suggestions on how to achieve the feature
Additional context
Yes please!
I have a POST request in which the server is weird, it is only case sensitive for the page
parameter and supports PascalCase for the rest of the parameters.
I thought using JsonNamingPolicy.CamelCase
would make all Request object properties use camelCase, but I was wrong, I misinterpreted the docs and it caused my response to always be page=1
, it took me 1 day of debugging to find this out, and in the beginning I didn't use [AliasAs]
because of my laziness.
private static readonly RefitSettings _camelCaseSettings = new() {
ContentSerializer = new SystemTextJsonContentSerializer(
new JsonSerializerOptions {
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
})
};
services.AddRefitClient<IWebService>(_camelCaseSettings)
So I'd really like to have a feature that allows global control of case, like this:
[CamelCaseNamingPolicy]
class Request
{ ... }
// or
services.AddRefitClient<IWebService>(/* add camelCase policy for application/x-www-form-urlencoded */)
Any updates on this? It's a little confusing that RefitSettings.ContentSerializer
ignores queries as objects.
Though I agree that this should probably have been done differently, this will have to be opt-in because it would be an incredible trolly breaking change otherwise