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

Query parameters with dots to camelCase #460

Open
angela-patino-yuli opened this issue Nov 16, 2022 · 11 comments
Open

Query parameters with dots to camelCase #460

angela-patino-yuli opened this issue Nov 16, 2022 · 11 comments
Assignees

Comments

@angela-patino-yuli
Copy link

Summary
A similar issue has been fixed for path parameters #413
Is it possible to have it for query params as well?
On my swagger.json file, If a query parameter has a dot in it (e.g. from.year) then swagger-typescript-api rewrites this to
"from.year"?: number; instead of "fromYear"

Expected

foobar = (
   query?: {
     /** @format int32 */
     "fromYear"?: number;
   },
   params: RequestParams = {},
 ) =>
   this.http.request<void, any>({
     path: `/api/list`,
     method: "GET",
     query: query,
     secure: true,
     ...params,
   });

Actual

 foobar = (
    query?: {
      /** @format int32 */
      "from.year"?: number;
    },
    params: RequestParams = {},
  ) =>
    this.http.request<void, any>({
      path: `/api/list`,
      method: "GET",
      query: query,
      secure: true,
      ...params,
    });
@js2me js2me self-assigned this Nov 17, 2022
@js2me
Copy link
Member

js2me commented Nov 18, 2022

@angela-patino-yuli can you share part of your schema with this query params?

@angela-patino-yuli
Copy link
Author

angela-patino-yuli commented Nov 18, 2022

Hi. Thanks for the quick response, and sorry for my delay.
Here is an example of the schema from swagger

"/users/list": {
      "get": {
        "tags": [
          "Items"
        ],
        "parameters": [
          {
            "name": "From.Year",
            "in": "query",
            "schema": {
              "type": "integer",
              "format": "int32"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success"
          }
        }
      }
    }
  },

@js2me
Copy link
Member

js2me commented Nov 18, 2022

@angela-patino-yuli I think this can broke server side logic for other users, need more research to find a better way to do that.

@angela-patino-yuli
Copy link
Author

thanks. if you need anything. let me know 😺

@js2me js2me mentioned this issue Nov 18, 2022
@adrivelasco
Copy link

adrivelasco commented Aug 2, 2023

@js2me hey, and what if I would like to keep dots? is there a way to disable it?

@mr-raccoon-dev
Copy link

@adrivelasco I dunno did you find a solution or not, but you can use version 12.x.x to queries with dots.
Looks like it was broken since 13.0.0 version.
In v12.0.4 query parameters with dots works fine.

@depsimon
Copy link
Contributor

@js2me it does indeed break server-side logic in my case at least.

The server expects dots in the parameter name.

In my case we have these parameters :

{
    "name": "artist.id",
    "in": "query",
    "description": "",
    "required": false,
    "deprecated": false,
    "allowEmptyValue": true,
    "schema": { "type": "integer" },
    "style": "form",
    "explode": false,
    "allowReserved": false
},
{
    "name": "artist.id[]",
    "in": "query",
    "description": "",
    "required": false,
    "deprecated": false,
    "allowEmptyValue": true,
    "schema": { "type": "array", "items": { "type": "integer" } },
    "style": "form",
    "explode": true,
    "allowReserved": false
},
{
    "name": "id",
    "in": "query",
    "description": "",
    "required": false,
    "deprecated": false,
    "allowEmptyValue": true,
    "schema": { "type": "integer" },
    "style": "form",
    "explode": false,
    "allowReserved": false
},
{
    "name": "id[]",
    "in": "query",
    "description": "",
    "required": false,
    "deprecated": false,
    "allowEmptyValue": true,
    "schema": { "type": "array", "items": { "type": "integer" } },
    "style": "form",
    "explode": true,
    "allowReserved": false
},

And the generated schema is

export interface Params {
  artistId?: number[];
  id?: number;
  "id[]"?: number[];
}

instead of

export interface Params {
  "artist.id"?: number;
  "artist.id[]"?: number[];
  id?: number;
  "id[]"?: number[];
}

@AirP0WeR
Copy link

Hi there!

12.0.4 fix my problem with dots. v13 has this bug.

@climam
Copy link

climam commented Mar 19, 2024

Hello, we are facing same issue. This change introduced in version 13 no longer allow us to use this library. Could you implement an option to disable this auto conversion to camelCase? Waiting for a fix we will stick with version 12.0.4.

Thanks

@nicky1038
Copy link

nicky1038 commented Apr 19, 2024

+1 to everyone who says this change breaks logic.
Renaming query parameters in types is not acceptable, as backend server expects them exactly as specified in Swagger schema.
I've made a PR #701 where I revert that change, I hope it'll be accepted some time :)

@Jahoda
Copy link

Jahoda commented Sep 6, 2024

Could it be possible to fix this issue, please?

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

No branches or pull requests

9 participants