Skip to content

RTK-Query Codegen: Camel case applied incorrectly in some situations #2181

@sbward

Description

@sbward

In my API I use a variation of camel casing that preserves uppercase in abbreviations. For example, userId becomes userID. Normally this is interpreted as camel case and I would not expect any transformations to be applied to the string.

The issue is that RTK-Query Codegen uses the lodash camelCase function, which converts userID to userId. Lodash's behavior in this regard has been controversial (see lodash/lodash#5045) and I think it would be better to use an alternative (like hump) which has the expected behavior.

Relevant code:

const isPureSnakeCase = /^[a-zA-Z][a-zA-Z0-9_]*$/.test(param.name);
const camelCaseName = camelCase(param.name);
const name = isPureSnakeCase && !allNames.includes(camelCaseName) ? camelCaseName : param.name;

Metadata

Metadata

Assignees

No one assigned

    Labels

    RTKQ-CodegenIssues related to the @rtk-query/codegen-openapi package.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions