PrimitiveProperty.fromJson constructor
Creates a PrimitiveProperty from a JSON Schema fragment.
Implementation
factory PrimitiveProperty.fromJson(Map<String, dynamic> json) {
late TPropertyType tPropertyType;
if (json['format'] == "binary") {
tPropertyType = TPropertyType.file;
} else if (json['format']?.toString().contains("date") == true) {
tPropertyType = TPropertyType.date;
} else {
tPropertyType = TPropertyType.values.firstWhere(
(e) {
return e.name == (json['type'].toString());
},
orElse: () {
return TPropertyType.string;
},
);
}
return PrimitiveProperty(
type: tPropertyType,
format: json['format'] as String?,
enumValues: (json['enum'] as List<dynamic>? ?? [])
.map((e) => e.toString())
.toList(),
defaultValue: json['default'],
nullable: json['nullable'] ?? false,
);
}