getExtensionMapper method
Implementation
String getExtensionMapper(
String suffix,
String name,
String parent,
Map? map,
String? parentList,
bool fromList, [
bool root = false,
]) {
if (map == null) return '';
final variable = map.keys;
final asClassNameResponse = '${suffix.snakeCase}_response';
final asClassNameEntity = '${suffix.snakeCase}_entity';
final apiClassName = ModelClassNameHelper.getClassName(
listClassNameMapper,
suffix,
name,
root,
true,
parent,
parentList != null && fromList ? parentList + parent : parent,
);
final apiClassNameResponse = '$apiClassName${root ? 'Response' : ''}';
final apiClassNameEntity = '$apiClassName${root ? 'Entity' : ''}';
final parentOfChild = parentList != null && fromList
? parentList + apiClassName
: apiClassName;
for (var e in variable) {
if (map[e] is Map) {
ModelClassNameHelper.getClassName(
listClassNameMapper,
suffix,
e.toString().pascalCase,
root,
false,
apiClassName,
parentOfChild,
);
}
}
for (var e in variable) {
final list = map[e];
if (list is List && list.isNotEmpty && list.first is Map) {
ModelClassNameHelper.getClassName(
listClassNameMapper,
suffix,
e.toString().pascalCase,
root,
false,
apiClassName,
parentOfChild,
);
}
}
final classString =
'''extension $apiClassNameResponse${root ? '' : 'Response'}Mapper on $asClassNameResponse.$apiClassNameResponse {
$asClassNameEntity.$apiClassNameEntity toEntity() => ${variable.isEmpty ? 'const' : ''} $asClassNameEntity.$apiClassNameEntity(${setVariableEntity(map, TypeMapper.toEntity)});
}
extension $apiClassNameEntity${root ? '' : 'Entity'}Mapper on $asClassNameEntity.$apiClassNameEntity {
$asClassNameResponse.$apiClassNameResponse toResponse() => ${variable.isEmpty ? 'const' : ''} $asClassNameResponse.$apiClassNameResponse(${setVariableEntity(map, TypeMapper.toResponse)});
}
${map.keys.map((e) => map[e] is Map ? getExtensionMapper(suffix, e.toString().pascalCase, apiClassName, map[e], parentOfChild, false) : '').join()}
${map.keys.map((e) => map[e] is List ? map[e] == null ? '' : (map[e] as List).isEmpty ? '' : (map[e] as List).first is! Map ? '' : getExtensionMapper(suffix, e.toString().pascalCase, apiClassName, (map[e] as List).first, parentOfChild, true) : '').join()}''';
return classString;
}