OpenAPITools / OpenAPITools/openapi-generator
[REQ] [Dart] Enums instead of Class models
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
When generating Dart code from OpenAPI specifications, enum types are generated as class models instead of proper Dart enums. This makes the code less idiomatic and harder to use with Dart's pattern matching and switch expressions.
For example, instead of generating proper Dart enums like:
enum Status {
active,
pending,
inactive
}
It generates class models like:
class Status {
static const active = Status._('active');
static const pending = Status._('pending');
static const inactive = Status._('inactive');
final String value;
const Status._(this.value);
}
Describe the solution you'd like
The generator should create proper Dart enums using the enum keyword for OpenAPI enum definitions. This would:
- Enable better static analysis
- Allow usage of Dart's enhanced enum features (pattern matching, switch expressions)
- Make the code more maintainable and idiomatic
- Improve code readability
Describe alternatives you've considered
The current class-based implementation works but lacks the benefits of native Dart enums. We could:
- Keep using class models but add utility methods to mimic enum behavior
- Generate both class model and enum, with conversion methods
- Use sealed classes instead
However, proper Dart enums would be the most straightforward and maintainable solution.
Additional context
- Using CLI tool for generation
- OpenAPI Generator version:7.10.0
- Flutter SDK version: 3.24.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CLI generation path for Dart and identify the templates responsible for OpenAPI enum definitions. Compare the current class-model output with the requested native enum output, then verify generated code against the Dart and Flutter versions mentioned in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, java, openapi
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100