Skip to content

feat(codegen): add operationIdTransformer option#5236

Open
aryaemami59 wants to merge 1 commit intoreduxjs:masterfrom
aryaemami59:feat/codegen/operationIdTransformer
Open

feat(codegen): add operationIdTransformer option#5236
aryaemami59 wants to merge 1 commit intoreduxjs:masterfrom
aryaemami59:feat/codegen/operationIdTransformer

Conversation

@aryaemami59
Copy link
Member

Summary

  • Add an operationIdTransformer config option to @rtk-query/codegen-openapi that controls how OpenAPI operationId values are transformed into endpoint names.

Motivation

  • @rtk-query/codegen-openapi currently passes every operationId through oazapfts, which applies lodash's camelCase.
    This mangles consecutive uppercase acronyms.
    For example, fetchMyJWTPlease becomes fetchMyJwtPlease, making it impossible to match the original operationId exactly.

This causes two categories of pain:

  1. filterEndpoints breaks on acronym-heavy names. If your schema has operationId: fetchMyJWTPlease, you must filter by 'fetchMyJwtPlease' (the mangled form) even though the schema says fetchMyJWTPlease. This is surprising and easy to get wrong. See remove implicit conversion to camel case of openapi operation id. #4322.
  2. Generated names silently diverge from the schema. Teams that use the operationId as a stable identifier (e.g. for analytics, logging, or cross-service contracts) find the camelCase conversion breaks their assumptions. See RTK-Query Codegen: Camel case applied incorrectly in some situations #2181.

Solution

  • Add operationIdTransformer?: 'camelCase' | 'none' | ((operationId: string) => string) to CommonOptions.
Value Behavior
'camelCase' (default) Existing behavior. Applies lodash's camelCase via oazapfts. Fully backwards-compatible.
'none' Uses the raw operationId verbatim, preserving exact casing from the schema.
(operationId: string) => string Applies a custom transform for full control.

When 'none' or a function is used, every operation must have an operationId defined. The codegen throws an informative error if any operation is missing one.

filterEndpoints is always matched against the transformed name, consistent regardless of which transformer is active.

Usage

Preserve exact casing. fetchMyJWTPlease stays fetchMyJWTPlease:

import type { ConfigFile } from "@rtk-query/codegen-openapi";

const config = {
  schemaFile: "./openapi.json",
  apiFile: "./src/emptyApi.ts",
  outputFile: "./src/api.ts",
  operationIdTransformer: "none",
} satisfies ConfigFile;

export default config;

Custom transform:

import type { ConfigFile } from "@rtk-query/codegen-openapi";

const config = {
  schemaFile: "./openapi.json",
  apiFile: "./src/emptyApi.ts",
  outputFile: "./src/api.ts",
  operationIdTransformer: (operationId) => operationId.replace(/^get/, "fetch"),
} satisfies ConfigFile;

export default config;

Related


PR #5174 by @issy proposed a boolean exactOperationIds flag. A boolean is simpler to configure but can only toggle between two fixed behaviors. operationIdTransformer is a strict superset: passing 'none' is equivalent to exactOperationIds: true, while the function form covers everything else. The implementation PR takes direct inspiration from #5174's approach and @issy will be added as a co-author of the commit.

@aryaemami59 aryaemami59 added this to the 3.0 milestone Feb 25, 2026
@aryaemami59 aryaemami59 self-assigned this Feb 25, 2026
@aryaemami59 aryaemami59 added the RTKQ-Codegen Issues related to the @rtk-query/codegen-openapi package. label Feb 25, 2026
@codesandbox
Copy link

codesandbox bot commented Feb 25, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 25, 2026

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit be58ecb:

Sandbox Source
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
rtk-esm-cra Configuration

Co-authored-by: Issy Szemeti <48881813+issy@users.noreply.github.com>
@aryaemami59 aryaemami59 force-pushed the feat/codegen/operationIdTransformer branch from fa9c5f7 to be58ecb Compare February 25, 2026 18:21
@netlify
Copy link

netlify bot commented Feb 25, 2026

Deploy Preview for redux-starter-kit-docs ready!

Name Link
🔨 Latest commit be58ecb
🔍 Latest deploy log https://app.netlify.com/projects/redux-starter-kit-docs/deploys/699f3dc3629f0b0007900a51
😎 Deploy Preview https://deploy-preview-5236--redux-starter-kit-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@aryaemami59 aryaemami59 marked this pull request as ready for review February 25, 2026 18:32
@issy
Copy link
Contributor

issy commented Feb 25, 2026

I'm glad this is gaining traction! Thanks for the acknowledgment. I like this idea

@aryaemami59
Copy link
Member Author

@issy

I'm glad this is gaining traction! Thanks for the acknowledgment. I like this idea

Glad to hear it, and thanks for the original PR. It's what got the ball rolling on this!

The function form already lets you plug in any transform today (e.g. a snake_case or PascalCase library), but named shorthands like 'PascalCase' or 'snake_case' could be added as non-breaking additions to the union type down the line if there's enough demand. The architecture is there for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

2 participants