OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Dart] list comparison for and map comparison for ==

Open
#15,763 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.