OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Dart] list comparison for and map comparison for ==
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
For generated models, comparison of nested objects that are a list always return false due to the == comparison not working for list of objects in dart. Also for Maps of <type, Object> the same issue.
openapi-generator version
6.6.0
Suggest a fix
If using Flutter, when usually is the case, using listEquals(this.list, other.list) and mapEquals(this.map, other.map) works.
Just have to 'import 'package:flutter/foundation.dart'; into the api.dart file.
E.g.
Obj({
required this.id,
this.data = const {},
this.photos = const [],
});
String id,
Map<String, Object> data;
List<PhotoObject>?;
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Obj &&
other.id == id &&
other.data == data &&
other.photos == photos
----- INTO ---------
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Obj &&
other.id == id &&
mapEquals(other.data, data) &&
listEquals(other.photos, photos)
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 by locating the Dart generator code that produces the generated api.dart model equality methods, then inspect how nested List and Map fields are compared. Use the issue's Obj example as the expected behavior and verify that generated models compare these collections by contents rather than identity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100