feat(codegen): migrate to oazapfts v7 #5228
feat(codegen): migrate to oazapfts v7 #5228Suto-Michimasa wants to merge 9 commits intoreduxjs:masterfrom
Conversation
- 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.
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
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:
|
✅ Deploy Preview for redux-starter-kit-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- 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.
| 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(); | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| 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); | ||
| } |
There was a problem hiding this comment.
7.5.0-alpha.5 exposes this under oazapfts/generate
| return res; | ||
| } | ||
|
|
||
| function preprocessComponents(ctx: OazapftsContext): void { |
There was a problem hiding this comment.
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.
Xiphe
left a comment
There was a problem hiding this comment.
LGTM! Will make sure to release 7.5 stable in the next 2 days
|
@Xiphe |
|
Hey @Suto-Michimasa Sorry I had planned to get it out before a vacation but eventually did not come around to it. |
Summary
PoC for migrating
@rtk-query/codegen-openapifrom oazapfts v6 to v7 and adding theenumStyleoption.This is the Option A (lazy type generation compatibility adapter) implementation discussed in #5225.
Approach
oazapfts v7 removed the
ApiGeneratorclass andoazapfts/generateexport entirely. Rather than usinggenerateAst(which generates all types upfront and would require AST-based transitive closure to work withfilterEndpoints), this PR adds a compatibility adapter that preserves v6's lazy type generation — type aliases are created on-demand when a$refis first encountered, sofilterEndpointsworks naturally.Related issues
enumStyleoption from oazapfts v7.3.0 #5223 —enumStylefeature request@rtk-query/codegen-openapi#5225 — Migration strategy discussion