getMissingFields method

List<String> getMissingFields(
  1. Map<String, dynamic> jsonMap
)

Implementation

List<String> getMissingFields(Map<String, dynamic> jsonMap) {
  final result = <String>[];

  void checkMap(Map<String, dynamic> map, String? parentPath) {
    map.forEach((key, value) {
      final fullPath = parentPath != null ? '$parentPath.$key' : key;
      if (value == null) {
        result.add(fullPath);
      } else if (value is Map<String, dynamic>) {
        checkMap(value, fullPath);
      } else if (value is List<dynamic>) {
        for (int i = 0; i < value.length; i++) {
          final itemPath = '$fullPath[$i]';
          if (value[i] is Map<String, dynamic>) {
            checkMap(value[i] as Map<String, dynamic>, itemPath);
          } else {
            result.add(itemPath);
          }
        }
      }
    });
  }

  checkMap(jsonMap, null);
  return result;
}