Swagger Codegen vs. OpenAPI Generator: Consistent polymorphic model generation in CI/CD
0 reputation · 02 Jun 2024, 18:36 UTC
When a team uses a repeatable CI/CD pipeline to generate SDKs from an OpenAPI 3.x spec, the mapping of oneOf and anyOf schemas to statically‑typed language models is a frequent source of drift. The OpenAPI Generator fork of Swagger Codegen supports a wide array of target languages, but each language’s template implements its own heuristic for polymorphism (sealed interfaces, union types, generic Object, etc.). Because these heuristics live in Mustache templates, a minor generator release can alter the generated class hierarchy without any visible change to the command‑line flags, leaving teams unable to pin a stable output. Moreover, the discriminator.mapping feature is honored inconsistently across languages, further complicating cross‑language parity.
Given this uncertainty, teams need a clear path to enforce a consistent polymorphic model strategy across Java, TypeScript, and Go while keeping the spec as the single source of truth. What approaches can be adopted to lock in a stable oneOf/anyOf mapping in a CI/CD pipeline? Which generator versions or template forks provide the most reliable behavior for this feature? Is there a forthcoming CLI option to select a polymorphism strategy explicitly?