extractTypeJson function
Implementation
@visibleForTesting
Map<String, dynamic> extractTypeJson(Object? eventParam) {
try {
final type = _extractType(eventParam);
if (type == "list") {
final runtimeType = eventParam.runtimeType.toString().toLowerCase();
var subtype = runtimeType.substring(
runtimeType.indexOf("<") + 1, runtimeType.indexOf(">"));
final isOptional = subtype.contains("?");
if (isOptional) {
subtype = subtype.substring(0, subtype.length - 1);
}
var children = <String>{};
if (subtype == "dynamic" || subtype == "object") {
(eventParam as Iterable).forEach((element) {
children.add(_extractType(element));
});
} else if ((eventParam as Iterable).length > 0) {
children.add(subtype);
}
if (isOptional) {
children.add("null");
}
return {"propertyType": type, "children": children.toList()};
} else if (type == "object") {
Map<String, dynamic> map = eventParam as Map<String, dynamic>;
var children = extractSchemaFromEventParams(eventParams: map);
return {"propertyType": type, "children": children};
} else {
return {
"propertyType": type,
};
}
} catch (e) {
print("Fialed to extrac schema from $eventParam");
return {
"propertyType": "unknown",
};
}
}