refit icon indicating copy to clipboard operation
refit copied to clipboard

Support CamelCase Query

Open lauglam opened this issue 2 years ago • 4 comments

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

lauglam avatar Mar 29 '22 09:03 lauglam

Yes please!

penev92 avatar Jun 20 '23 07:06 penev92

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 */)

CodingOctocat avatar Dec 04 '23 13:12 CodingOctocat

Any updates on this? It's a little confusing that RefitSettings.ContentSerializer ignores queries as objects.

carlosharrycrf avatar Feb 26 '24 16:02 carlosharrycrf

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

anaisbetts avatar Feb 26 '24 19:02 anaisbetts