swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

Query parameters with dots to camelCase

Open angela-patino-yuli opened this issue 2 years ago • 11 comments

Summary A similar issue has been fixed for path parameters https://github.com/acacode/swagger-typescript-api/issues/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,
    });

angela-patino-yuli avatar Nov 16 '22 16:11 angela-patino-yuli

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

js2me avatar Nov 18 '22 06:11 js2me

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"
          }
        }
      }
    }
  },

angela-patino-yuli avatar Nov 18 '22 12:11 angela-patino-yuli

@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.

js2me avatar Nov 18 '22 12:11 js2me

thanks. if you need anything. let me know 😺

angela-patino-yuli avatar Nov 18 '22 12:11 angela-patino-yuli

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

adrivelasco avatar Aug 02 '23 03:08 adrivelasco

@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.

mr-raccoon-dev avatar Sep 05 '23 13:09 mr-raccoon-dev

@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[];
}

depsimon avatar Sep 26 '23 08:09 depsimon

Hi there!

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

AirP0WeR avatar Oct 31 '23 11:10 AirP0WeR

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

climam avatar Mar 19 '24 16:03 climam

+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 https://github.com/acacode/swagger-typescript-api/pull/701 where I revert that change, I hope it'll be accepted some time :)

nicky1038 avatar Apr 19 '24 20:04 nicky1038