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

TS Query Builder always uses camelCase naming, but Swagger Spec requires PascalCase when using [FromQuery] #231

Open
max-scopp opened this issue Nov 7, 2024 · 2 comments
Labels
bug Something isn't working gridify-client Issues related to the TypeScript client

Comments

@max-scopp
Copy link

Version

2.15.0

Details

Using Gridify and heyapi to get the query options from the URL like so:

    public async Task<IActionResult> GetTasks([FromQuery] GridifyQuery query)

produces the following client type

export type GetApiTasksData = {
    query?: {
        Filter?: string;
        OrderBy?: string;
        Page?: number;
        PageSize?: number;
    };
};

However, the TS Gridify Query builder produces always lowercased query options. This makes the types incompatible without additional mapping or recasting.

Funnily enough, at runtime, it doesn't matter whether the query params are PascalCase or camelCase.
I am assuming that this is just missing something to tell swagger.

Steps to reproduce

  • Acquire the query options using [FromQuery] like above.
  • Check out the Swagger Schema.
@max-scopp max-scopp added the bug Something isn't working label Nov 7, 2024
@alirezanet
Copy link
Owner

alirezanet commented Nov 7, 2024

Hi @max-scopp,
I have so many questions about this, and unfortunately, I'm not familiar with Heyapi. To make it short, is there any specific error you're facing? As you said, query strings are not case-sensitive, so you shouldn't have any problem. Do you have any custom JSON serializer settings for your project? (I'm trying to understand the relation between swagger and the GridifyClient query, do you just want to fix the spec?)

@alirezanet alirezanet added the gridify-client Issues related to the TypeScript client label Nov 7, 2024
@max-scopp
Copy link
Author

Thank you for taking the time to look into this.

To clarify, we’re not using any specific converters that might interfere with serialization.

In brief, Heyapi utilizes the Swagger JSON to auto-generate a client that allows data fetching without manually managing interfaces, requests, or transformations (like converting strings to Date objects). It’s quite effective at sticking to the Swagger spec, which, in this case, results in TypeScript types that aren't compatible with Gridify’s QueryBuilder.

I’ll outline the situation as I understand it (from my experience and input from a backend colleague):

By default, .NET converts DTO properties in request and response bodies to camelCase.
This default also informs Swagger for requests that involve a request body.
For GET requests, however, we rely on search params for query options instead of a request body.
It seems that .NET lacks a configuration to enforce camelCase naming conventions for these query parameters.
As a result, Swagger leaves the DTO property names as they are, leading to PascalCase names in the spec, which aligns with .NET standards.
So, while query parameters are case-insensitive at runtime, Heyapi reads the Swagger spec exactly as written and generates corresponding TypeScript types with PascalCase, which makes them incompatible with Gridify’s QueryBuilder.

In short, the issue seems to be that Swagger is missing configuration to enforce camelCase for query parameters in the generated spec. I’ll add a minimal demo tomorrow when I’m back at work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gridify-client Issues related to the TypeScript client
Projects
None yet
Development

No branches or pull requests

2 participants