Skip to content

feat(codegen): migrate to oazapfts v7 #5228

Open
Suto-Michimasa wants to merge 16 commits intoreduxjs:masterfrom
Suto-Michimasa:feat/codegen-oazapfts-v7-enum-style
Open

feat(codegen): migrate to oazapfts v7 #5228
Suto-Michimasa wants to merge 16 commits intoreduxjs:masterfrom
Suto-Michimasa:feat/codegen-oazapfts-v7-enum-style

Conversation

@Suto-Michimasa
Copy link
Copy Markdown

@Suto-Michimasa Suto-Michimasa commented Feb 19, 2026

Summary

Migrate @rtk-query/codegen-openapi from oazapfts v6 to v7.5.0 stable.

Approach

oazapfts v7 removed the ApiGenerator class that codegen previously depended on. Through collaboration with the oazapfts maintainer (@Xiphe) in oazapfts#830, the necessary APIs were exported as stable subpath entries:

  • oazapfts/contextcreateContext, withMode
  • oazapfts/generategetTypeFromSchema, getTypeFromResponse, getResponseType, getSchemaFromContent, getOperationName, preprocessComponents
  • @oazapfts/resolveresolve, resolveArray, isReference, getReferenceName

This replaces the previous compatibility adapter with direct API usage. The oazapfts plugin system was also evaluated but the direct API is a better fit since RTK codegen replaces the entire output structure rather than extending it (details).

Changes

All 74 tests pass with no snapshot diffs.

Related issues

@codesandbox
Copy link
Copy Markdown

codesandbox bot commented Feb 19, 2026

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@Suto-Michimasa Suto-Michimasa changed the title feat(codegen): oazapfts v7 移行と enumStyle オプションの追加 feat(codegen): migrate to oazapfts v7 and add enumStyle option Feb 19, 2026
@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci bot commented Feb 19, 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 74c035a:

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

@netlify
Copy link
Copy Markdown

netlify bot commented Feb 19, 2026

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

Name Link
🔨 Latest commit 74c035a
🔍 Latest deploy log https://app.netlify.com/projects/redux-starter-kit-docs/deploys/69d3c88738457200083ea8ca
😎 Deploy Preview https://deploy-preview-5228--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 added the RTKQ-Codegen Issues related to the @rtk-query/codegen-openapi package. label Feb 19, 2026
@Suto-Michimasa Suto-Michimasa changed the title feat(codegen): migrate to oazapfts v7 and add enumStyle option feat(codegen): migrate to oazapfts v7 Feb 19, 2026
Comment on lines +28 to +40
export function isReference(
obj: unknown
): obj is OpenAPIV3.ReferenceObject {
return typeof obj === 'object' && obj !== null && '$ref' in (obj as any);
}

export function getReferenceName(
obj: unknown
): string | undefined {
if (isReference(obj)) {
return obj.$ref.split('/').pop();
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oazapfts/oazapfts#826 creates a @oazapfts/resolve package exposing these and other schema related helpers.

Comment on lines +107 to +116
function getTypeFromResponse(
ctx: OazapftsContext,
response: OpenAPIV3.ResponseObject | OpenAPIV3.ReferenceObject,
onlyMode?: OnlyMode
): ts.TypeNode {
const resolved = resolve(response, ctx);
if (!resolved.content) return keywordType.void;
const schema = getSchemaFromContent(resolved.content);
return getTypeFromSchema(onlyMode ? withMode(ctx, onlyMode) : ctx, schema);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7.5.0-alpha.5 exposes this under oazapfts/generate

return res;
}

function preprocessComponents(ctx: OazapftsContext): void {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7.5.0-alpha.5 does this within createContext

Copy link
Copy Markdown

@Xiphe Xiphe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Will make sure to release 7.5 stable in the next 2 days

@Suto-Michimasa
Copy link
Copy Markdown
Author

@Xiphe
Hey, just wondering how the 7.5.0 stable release is coming along?

@Xiphe
Copy link
Copy Markdown

Xiphe commented Mar 16, 2026

Hey @Suto-Michimasa

Sorry I had planned to get it out before a vacation but eventually did not come around to it.
I'm back to work now and plan to finalize the release in the coming days.

Xiphe added a commit to oazapfts/oazapfts that referenced this pull request Mar 20, 2026
In order to unblock Redux Toolkit from upgrading to the latest oazapfts,
this focuses on making the `oazapfts/generate` submodule a reliable public
integration surface for schema/type-generation helpers outside the default
codegen pipeline, with follow-up fixes around exported helpers and preprocess
flow needed by the RTK migration path.

ref: #830
ref: reduxjs/redux-toolkit#5228

--- 

* feat(codegen): add filterEndpoint plugin hook

in order to allow plugins to customize which endpoints are
being generated and which are not.

ref https://github.com/reduxjs/redux-toolkit/issues/5225\#issuecomment-3938309171

* test(codegen): add test for include/exclude options

* refactor(codegen): move include/exclude option handling into plugin

dogfood, mjummy

* refactor(codegen): change generateMethod hook from waterfall to bail

In order to allow plugins to fully own method generation and skip the
default implementation entirely, `generateMethod` is now a bail hook
(first-return-wins) instead of a waterfall.

The default oazapfts method generation has been moved into a LAZY
internal plugin (`defaultGenerateMethodPlugin`) and serves as the
fallback when no other plugin claims the endpoint. Plugins return
`undefined` to delegate, or an array to claim generation.

ref: reduxjs/redux-toolkit#5225 (comment)

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(codegen): add refineMethod waterfall hook for per-endpoint transforms

In order to allow plugins to modify, rename, annotate or filter generated
methods without claiming full generation ownership, a new `refineMethod`
waterfall hook is introduced. It runs after `generateMethod` (bail) for
each endpoint and receives the generated `FunctionDeclaration[]` to
transform and return.

This also extracts the shared endpoint argument shape into
`UNSTABLE_EndpointHookArgs` to reduce type duplication across hooks.

ref: reduxjs/redux-toolkit#5225 (comment)

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(codegen): add composeSource/refineSource plugin hooks

In order to allow plugins to fully customize (or replace) top-level
source statement composition, which was previously hardcoded in
generateApi. The default composition is now provided by an internal
LAZY plugin (defaultComposeSourcePlugin), so user plugins can bail
composeSource and take full control. Banner insertion and
createSourceFile construction remain fixed in core flow.

ref: #830 (comment)
Co-authored-by: Cursor <cursoragent@cursor.com>

* refactor(codegen): move method name de-collision into generation time

In order to allow the generate/refine method hooks to accept ts.Statement[]
instead of ts.FunctionDeclaration[], name collision handling must happen
at name-reservation time rather than as a post-processing step in
defaultComposeSource.

operationNames (Map<string, number>) is added to OazapftsContext and passed
to getOperationNames, which now reserves each name as it is computed.
The reserveOperationName helper ensures generated suffixes never collide
with other operation names already in the map (including explicitly-suffixed
operationIds like "hello1" or "hello2").

defaultComposeSource no longer calls dedupeMethodNames.

ref: #830 (comment)
Co-authored-by: Cursor <cursoragent@cursor.com>

* refactor(codegen): loosen generateMethod/refineMethod to ts.Statement[]

In order to allow plugins to return arbitrary top-level statements
from generateMethod, not just function declarations, so that custom
output formats are no longer constrained to ts.FunctionDeclaration.

ref: #830 (comment)
Co-authored-by: Cursor <cursoragent@cursor.com>

* refactor(codegen): rename getTypeForSchema to getTypeFromSchema

In order to align the file name with the exported function name
`getTypeFromSchema`, making imports and navigation more consistent.

* docs(codegen): mark supportDeepObjects as deprecated

In order to communicate to future contributors that
supportDeepObjects is no longer in use since v7.0 dropped
support for the Swagger-to-OpenAPI conversion path that
relied on it.

* refactor(codegen): move getTypeFromSchema into its own top-level module

In order to make the schema type resolution logic available outside of
the generate pipeline and to establish clearer module boundaries within
the codegen package, the getTypeFromSchema cluster of files is extracted
from src/generate/ into a dedicated src/getTypeFromSchema/ directory.
A barrel index.ts re-exports getTypeFromSchema as the public entry point.
Import paths in the generate/ consumers are updated accordingly.

ref: #830 (comment)

* refactor(codegen): propagate onlyMode via context instead of function params

In order to avoid threading the `onlyMode` argument through every level
of the type generation call stack, it is now stored as `mode` on a
derived context object created via the new `withMode()` helper.

`withMode()` does a shallow clone of the context, so all mutable shared
state (aliases, refs, etc.) is still shared across calls while each
frame carries its own mode snapshot — without needing save/restore logic.

Entry points (`getRefAlias`, `generateClientMethod`, `getTypeFromResponses`)
now derive a mode-scoped context. Intermediate functions
(`getTypeFromSchema`, `getBaseTypeFromSchema`, `getUnionType`,
`getTypeFromProperties`) drop the `onlyMode` parameter and read
`ctx.mode` directly.

Also fixes a long-standing bug in `generateApi` where the resolved schema
object was incorrectly passed as the `ignoreDiscriminator?: boolean`
argument to `getRefAlias`, causing `allSchemas` to generate base type
names suffixed with "Base" instead of the correct names.

Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(codegen): expose generate subpath api with full tests

In order to make the generate module a reliable public entrypoint,
this change stabilizes its exports and adds direct tests for exported
schema and generation helpers.

ref: #830 (comment)

* feat(codegen): stabilize plugin api naming

In order to make plugin integration a stable part of the codegen surface,
this removes the UNSTABLE_ prefixes from plugin types, helpers, and options.

Co-authored-by: Cursor <cursoragent@cursor.com>

* style: apply prettier

* fix(codegen): build generate export

ref https://github.com/oazapfts/oazapfts/pull/830\#pullrequestreview-3858005073

* fix(codegen): guard against undefined deprecatedLegacyName

In order to prevent returning `undefined` from `getOperationName`
when `DEPRECATED_legacyName` flag is set but no legacy name exists
in the computed names object.

* feat(codegen): export getTypeFromResponse as part of public API

In order to allow consumers to resolve a single response object to its
TypeScript type node directly, without needing the full responses map.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(codegen): move preprocessComponents call into createContext

In order to ensure component preprocessing is part of context
initialization rather than a separate concern in the API generation
pipeline, the call is moved from generateApi into createContext.

ref: #830 (comment)

* Revert "feat(codegen): stabilize plugin api naming"

This reverts commit 8addaa8.

* Revert "fix(codegen): move preprocessComponents call into createContext"

This reverts commit 597aa78.

* feat(codegen): move preprocessComponents to generate and export from oazapfts/generate

In order to allow consumers (e.g. RTK codegen) that use createContext +
getTypeFromSchema directly without generateApi to call preprocessComponents
themselves when needed. Co-locates the logic with the generate pipeline and
adds comprehensive tests.

ref: #830 (comment)

* style: apply prettier

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
- Updated oazapfts dependency from v6.4.0 to v7.3.0 in package.json and yarn.lock.
- Introduced oazapfts-compat.ts to adapt to breaking changes in oazapfts v7, replacing the ApiGenerator with OazapftsAdapter.
- Refactored generate.ts to utilize the new compatibility layer.
- Updated TypeScript version handling in index.ts for compatibility with oazapfts v7.
- Adjusted type generation logic to ensure backward compatibility with existing code.
- Fixed optional properties in generated types to be required where necessary in test snapshots.
- Updated oazapfts dependency from v7.3.0 to v7.0.0 in both package.json and yarn.lock to ensure compatibility with existing code.
- Adjusted related versioning and checksums accordingly.
- Updated oazapfts dependency to v7.5.0-alpha.3 in package.json and yarn.lock.
- Introduced new utility functions for operation name generation and deep object support.
- Removed the deprecated oazapfts-compat.ts file and refactored generate.ts to utilize the new public API.
- Enhanced type generation logic to support TypeScript enums based on the useEnumType option.
- Updated tests to reflect changes in type generation and added new tests for enum generation.
- Removed unnecessary mapping logic for discriminator properties in makeDiscriminatorPropertiesRequired function.
- Streamlined the process of making discriminator properties required for child schemas.
- Improved code readability by eliminating redundant checks and variables.
…an up tests

- Eliminated the makeDiscriminatorPropertiesRequired function to simplify schema processing.
- Updated tests to remove unnecessary snapshot expectations and adjusted generated types to make allowance_type properties optional.
- Improved overall code clarity and maintainability.
- Updated oazapfts dependency to v7.5.0-alpha.5 in package.json and yarn.lock.
- Refactored generate.ts to improve type resolution logic and removed unused preprocessing functions.
- Enhanced import statements for better clarity and maintainability.
…ersion enforcement

- Removed the getOperationName utility function and updated imports to use the version from oazapfts/generate.
- Simplified TypeScript version enforcement logic in index.ts for better clarity and reliability.
- Enhanced overall code organization by removing unused files and improving import statements.
- Updated the context creation in generate.ts to ensure proper handling of the useEnumType option.
- Enhanced code clarity by restructuring the parameters passed to createContext.
- Updated oazapfts dependency to v7.5.0-alpha.6 in package.json and yarn.lock.
- Added preprocessComponents function call in generate.ts to improve component processing during API generation.
- Refined import statements for better clarity and maintainability.
- Updated oazapfts dependency to v7.5.0 in both package.json and yarn.lock to reflect the latest stable version.
- Adjusted checksums in yarn.lock for consistency with the new version.
@Suto-Michimasa Suto-Michimasa marked this pull request as ready for review March 21, 2026 08:55
@Suto-Michimasa Suto-Michimasa force-pushed the feat/codegen-oazapfts-v7-enum-style branch from f10756e to 30e3ac4 Compare March 21, 2026 08:56
@aryaemami59
Copy link
Copy Markdown
Member

I believe the PR description needs to be updated.

@Suto-Michimasa
Copy link
Copy Markdown
Author

@aryaemami59
Updated, thanks!

Comment thread packages/rtk-query-codegen-openapi/src/generate.ts Outdated
Comment thread packages/rtk-query-codegen-openapi/src/generate.ts Outdated
Comment thread packages/rtk-query-codegen-openapi/src/generate.ts Outdated
Comment thread packages/rtk-query-codegen-openapi/src/generate.ts Outdated
Comment thread packages/rtk-query-codegen-openapi/src/generate.ts Outdated
Comment thread packages/rtk-query-codegen-openapi/test/generateEndpoints.test.ts
@Suto-Michimasa
Copy link
Copy Markdown
Author

@aryaemami59
Thanks for your approval! When will you merge this PR?
I would like to work on issue #5223

Copy link
Copy Markdown
Member

@aryaemami59 aryaemami59 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, everything looks good, but I would feel much more confident merging this if another team member reviewed 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

Development

Successfully merging this pull request may close these issues.

Discussion: Migration strategy for oazapfts v6 → v7 in @rtk-query/codegen-openapi

3 participants