Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CamelCase Query #1333

Open
lauglam opened this issue Mar 29, 2022 · 5 comments · May be fixed by #1712
Open

Support CamelCase Query #1333

lauglam opened this issue Mar 29, 2022 · 5 comments · May be fixed by #1712

Comments

@lauglam
Copy link

lauglam commented Mar 29, 2022

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

@penev92
Copy link

penev92 commented Jun 20, 2023

Yes please!

@CodingOctocat
Copy link

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

@carlosharrycrf
Copy link

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

@anaisbetts
Copy link
Member

anaisbetts commented Feb 26, 2024

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

@tcortega
Copy link
Contributor

tcortega commented Jun 4, 2024

@ChrisPulman this should be closed

@ChrisPulman ChrisPulman linked a pull request Jun 9, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants