Skip to content

Support CamelCase Query #1333

Closed
Closed

Description

@p2mm2p

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

Activity

  1. penev92 commented on Jun 20, 2023

    @penev92

    Yes please!

  2. CodingOctocat commented on Dec 4, 2023

    @CodingOctocat

    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 */)
  3. LosLobosDev commented on Feb 26, 2024

    @LosLobosDev

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

  4. anaisbetts commented on Feb 26, 2024

    @anaisbetts
    Member

    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

  5. tcortega commented on Jun 4, 2024

    @tcortega
    Contributor

    @ChrisPulman this should be closed

  6. github-actions commented on Jul 5, 2024

    @github-actions

    This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  7. locked as resolved and limited conversation to collaborators on Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions