generateUnsafeDart method
generateUnsafeDart will generate all classes and append one after another
in a single string. The rawJson
param is assumed to be a properly
formatted JSON string. The dart code is not validated so invalid dart code
might be returned
Implementation
DartCode generateUnsafeDart(String rawJson) {
final jsonRawData = decodeJSON(rawJson);
final astNode = parse(rawJson, Settings());
List<Warning> warnings =
_generateClassDefinition(_rootClassName, jsonRawData, "", astNode);
// after generating all classes, replace the omited similar classes.
allClasses.forEach((c) {
final fieldsKeys = c.fields.keys;
fieldsKeys.forEach((f) {
final typeForField = c.fields[f];
if (typeForField != null) {
if (sameClassMapping.containsKey(typeForField.name)) {
c.fields[f]!.name = sameClassMapping[typeForField.name]!;
}
}
});
});
return new DartCode(
allClasses.map((c) => c.toString()).join('\n'), warnings);
}