feat(gen): support non-primitive enums with sum types#1597
Merged
ernado merged 2 commits intoogen-go:mainfrom Nov 30, 2025
Merged
feat(gen): support non-primitive enums with sum types#1597ernado merged 2 commits intoogen-go:mainfrom
ernado merged 2 commits intoogen-go:mainfrom
Conversation
Generate proper sum types for object enums where each enum value becomes a concrete struct variant. Features: - Automatic discriminator field detection for value-based discrimination - Concrete struct types for each enum value (e.g., ObjectEnumFoo, ObjectEnumBar) - Sum type with Type field for variant switching - Full JSON encoding/decoding with value-based discrimination - Getter/setter methods for type-safe variant access For array enums, falls back to jx.Raw since array items typically don't have discriminator fields. Fixes ogen-go#1596
ad6cfa5 to
4ca1e72
Compare
The gocritic linter flagged the unnamed return values in the findEnumDiscriminator function. Named the return values as fieldName and values for better documentation.
ernado
approved these changes
Nov 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Generate proper sum types for object enums where each enum value becomes a concrete struct variant.
Features:
ObjectEnumFoo,ObjectEnumBar)Typefield for variant switchingFor array enums, falls back to
jx.Rawsince array items typically don't have discriminator fields.Example
Given this schema:
Generates:
Test plan
Fixes #1596