Skip to content

feat(codegen): migrate to oazapfts v7 #5228

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

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

Conversation

@Suto-Michimasa
Copy link

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

Summary

PoC for migrating @rtk-query/codegen-openapi from oazapfts v6 to v7 and adding the enumStyle option.
This is the Option A (lazy type generation compatibility adapter) implementation discussed in #5225.

Approach

oazapfts v7 removed the ApiGenerator class and oazapfts/generate export entirely. Rather than using generateAst (which generates all types upfront and would require AST-based transitive closure to work with filterEndpoints), this PR adds a compatibility adapter that preserves v6's lazy type generation — type aliases are created on-demand when a $ref is first encountered, so filterEndpoints works naturally.

Related issues

- 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.
@codesandbox
Copy link

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

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 f214959:

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

@netlify
Copy link

netlify bot commented Feb 19, 2026

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

Name Link
🔨 Latest commit f214959
🔍 Latest deploy log https://app.netlify.com/projects/redux-starter-kit-docs/deploys/69a2b52a4b9ff40008686bb0
😎 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
- 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.
@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

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.

- 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.
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

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

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

- 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.
Copy link

@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
Author

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

@Xiphe
Copy link

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.

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