OpenAPITools / OpenAPITools/openapi-generator

✨ Feature Request: Add freezed as an alternative to built_value in Dart/Dio & Dart generators

Open
#21,837 1 comment 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Background

Currently, the Dart and Dart-Dio generators in OpenAPI Generator use built_value
for model generation. While built_value is a solid library, it has some limitations and additional boilerplate requirements that make it less convenient for many Dart/Flutter developers.

The Flutter ecosystem has widely adopted freezed
as the preferred code generation library for immutable data classes, pattern matching, union types, and null-safety.

Supporting freezed alongside or as an alternative to built_value would significantly improve the developer experience and adoption of OpenAPI Generator in Dart/Flutter projects.

Why Freezed?

✅ Better integration with Flutter/Dart ecosystem: Freezed is now the standard for immutable classes in Dart/Flutter.

✅ Less boilerplate: Provides a cleaner API with annotations and code generation.

✅ Equatable built-in: Automatic == and hashCode generation without extra packages.

✅ JSON serialization: Seamless integration with json_serializable.

✅ Union/sealed classes: Helpful for handling API response states (success, error, etc.).

✅ Null-safety first: Fully compatible with Dart’s null safety.

Proposed Solution

Add a generator flag (similar to --use-built-value) to enable freezed models, e.g.:

openapi-generator-cli generate
-i openapi.yaml
-g dart-dio
-o ./lib/api
--additional-properties=useFreezed=true

Generated models should:

Use @freezed annotations.

Use @JsonSerializable() integration for JSON parsing.

Include part 'model.freezed.dart'; and part 'model.g.dart';.

Replace built_value style factories with Freezed constructors.

Example (instead of built_value style):


part 'user.freezed.dart';
part 'user.g.dart';

@freezed
class User with _$User {
  const factory User({
    required String id,
    String? name,
    String? email,
  }) = _User;

  factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
}```

References

freezed package: https://pub.dev/packages/freezed



Would you accept a PR that adds freezed support as an option alongside built_value?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Dart and Dart-Dio generator entry points and the existing --use-built-value option. Compare current generated models with the proposed Freezed example, then verify that the CLI option, annotations, JSON serialization parts, constructors, and generated output meet the requested behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, flutter
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.