acacode / swagger-typescript-api

Generate the API Client for Fetch or Axios from an OpenAPI Specification
MIT License
3.23k stars 353 forks source link

Query parameters with dots to camelCase #460

Open angela-patino-yuli opened 1 year ago

angela-patino-yuli commented 1 year ago

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,
    });
js2me commented 1 year ago

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

angela-patino-yuli commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

thanks. if you need anything. let me know 😺

adrivelasco commented 1 year ago

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

mr-raccoon-dev commented 1 year ago

@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 commented 11 months ago

@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 commented 10 months ago

Hi there!

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

climam commented 6 months ago

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 commented 5 months ago

+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 :)

Jahoda commented 1 week ago

Could it be possible to fix this issue, please?