-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
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, sofilterEndpointsworks 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
- 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?
- Is it worth coordinating with @Xiphe on what RTK codegen would need from the plugin API?
- Should the v7 migration be a separate PR from
enumStyle? The migration is a prerequisite, but splitting might make review easier.
Related
- feat(codegen): Expose
enumStyleoption from oazapfts v7.3.0 #5223 —enumStylefeature request - Oazapfts will get plugins #4265 — oazapfts Plugin System notification (maintainer discussion)
- Update oazapfts to 6.1 #4588 — Previous oazapfts update (v6.1)
- oazapfts#805 — Plugin System PR
- oazapfts#823 —
enumStylein oazapfts
@Xiphe Thanks for the offer! Would love to collaborate.
PR #5228 currently reimplements lazy type generation using createContext + UNSTABLE_cg. The key hooks RTK codegen would need:
-
Lazy/on-demand type generation — types created per
$refas endpoints are processed (not all upfront), sofilterEndpointsworks naturally - Per-endpoint code generation control — select which operations to generate
-
Access to schema-to-type mapping — discriminator patterns, readOnly/writeOnly,
unionUndefined
Happy to use the current adapter as a bridge until the plugin API covers these.
cc @aryaemami59 @markerikson — any thoughts?