parseYamlModel function
Model
parseYamlModel(
- YamlMap yamlMap
)
Implementation
Model parseYamlModel(YamlMap yamlMap) {
final name = yamlMap['name'] as String;
final fields = <Field>[];
final enums = <EnumDefinition>[];
final yamlFields = yamlMap['fields'] as YamlMap;
yamlFields.forEach((key, value) {
final fieldName = key as String;
final fieldType = value['type'] as String;
final annotations =
(value['annotations'] as YamlList?)?.cast<String>() ?? [];
final isRequired = value['required'] as bool? ?? false;
final isEnum = value['enum'] as bool? ?? false;
final serializedName = value['serialized_name'] as String?;
final example = value['example'] as String?;
fields.add(Field(
name: fieldName,
type: fieldType,
annotations: annotations,
serializedName: serializedName,
isRequired: isRequired,
isEnum: isEnum,
example: example,
));
});
final yamlEnums = yamlMap['enums'] as YamlMap?;
if (yamlEnums != null) {
yamlEnums.forEach((key, value) {
final enumName = key as String;
final enumValues = (value as YamlList).cast<String>();
enums.add(EnumDefinition(name: enumName, values: enumValues));
});
}
FileAttachment? fileAttachment;
final fileAttachmentConfig = yamlMap['file_attachment'] as YamlMap?;
if (fileAttachmentConfig != null) {
fileAttachment =
FileAttachment(type: fileAttachmentConfig['type'] as String);
}
return Model(
name: name,
fields: fields,
enums: enums,
fileAttachment: fileAttachment,
);
}