buildDynamicVersionMap function
Builds a map of base activity type -> highest versioned activity type by scanning all string values in the swagger JSON for ACTIVITY_TYPE_* patterns.
Implementation
Map<String, String> buildDynamicVersionMap(
List<Map<String, dynamic>> rawSpecs) {
final allActivityTypes = <String>{};
void collect(dynamic value) {
if (value is String && value.startsWith('ACTIVITY_TYPE_')) {
allActivityTypes.add(value);
} else if (value is Map) {
for (final v in value.values) collect(v);
} else if (value is List) {
for (final v in value) collect(v);
}
}
for (final spec in rawSpecs) {
collect(spec);
}
final baseToHighest = <String, (int, String)>{};
final versionPattern = RegExp(r'^(.+)_V(\d+)$');
for (final activityType in allActivityTypes) {
final match = versionPattern.firstMatch(activityType);
if (match != null) {
final base = match.group(1)!;
final version = int.parse(match.group(2)!);
if (!baseToHighest.containsKey(base) ||
version > baseToHighest[base]!.$1) {
baseToHighest[base] = (version, activityType);
}
}
}
return baseToHighest.map((base, record) => MapEntry(base, record.$2));
}