swagger-typescript-api
swagger-typescript-api copied to clipboard
Query parameters with dots to camelCase
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 can you share part of your schema with this query params?
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 I think this can broke server side logic for other users, need more research to find a better way to do that.
thanks. if you need anything. let me know 😺
@js2me hey, and what if I would like to keep dots? is there a way to disable it?
@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.
@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[];
}
Hi there!
12.0.4 fix my problem with dots. v13 has this bug.
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
+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 :)