Skip to content

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

@Suto-Michimasa

Description

@Suto-Michimasa

Context

To support enumStyle (#5223), we need to upgrade oazapfts from v6 to v7. However, v7 removes the ApiGenerator class and oazapfts/generate export path entirely — the semi-official APIs that codegen currently depends on. The new public API is limited to createContext (oazapfts/context), UNSTABLE_cg, and generateAst (oazapfts).

In #4265, @Xiphe notified that v7 would remove these APIs, and a Plugin System is in early development (oazapfts#805).

Migration options

Option A: Reimplement lazy type generation locally

Compatibility adapter (~400 lines) using v7's createContext + UNSTABLE_cg, reimplementing the removed ApiGenerator behavior.

  • Pro: Preserves v6's lazy architecture — types are created on-demand per $ref, so filterEndpoints works naturally.
  • Con: ~400 lines of type generation logic that needs manual sync when oazapfts evolves.

Option B: Use generateAst + post-filter unreferenced types

Use v7's generateAst(ctx) to generate all types upfront, then filter out types not referenced by selected endpoints.

  • Pro: Delegates type generation to oazapfts — bug fixes and new features are inherited automatically.
  • Con: Requires AST-based transitive closure to determine referenced types. Circular references and discriminator patterns make this non-trivial.

Proof of concept

I have a working implementation of Option A that passes all 73 existing tests, including enumStyle: 'union' | 'enum' | 'as-const' support and proper handling of discriminator patterns, readOnly/writeOnly, and unionUndefined. Happy to share as a draft PR, or pivot to another approach.

Questions

  1. Which migration approach is preferred? Option A is ready now but adds maintenance; Option B delegates more but requires filter logic. Or should we wait for the Plugin System (Oazapfts will get plugins #4265) instead?
  2. Is it worth coordinating with @Xiphe on what RTK codegen would need from the plugin API?
  3. Should the v7 migration be a separate PR from enumStyle? The migration is a prerequisite, but splitting might make review easier.

Related

Pinned by aryaemami59

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions