Add DataType to schema
This is to make the data type supported explicit in the CLI
@@ -22,7 +22,9 @@ use grid_sdk::protocol::schema::payload::{
Action, SchemaCreateAction, SchemaCreateBuilder, SchemaPayload, SchemaPayloadBuilder,
SchemaUpdateAction, SchemaUpdateBuilder,
};
-use grid_sdk::protocol::schema::state::{DataType, PropertyDefinition, PropertyDefinitionBuilder};
+use grid_sdk::protocol::schema::state::{
+ DataType as StateDataType, PropertyDefinition, PropertyDefinitionBuilder,
+};
use grid_sdk::protos::IntoProto;
use reqwest::Client;
@@ -42,7 +44,7 @@ pub struct GridSchemaSlice {
pub struct GridPropertyDefinitionSlice {
pub name: String,
pub schema_name: String,
- pub data_type: String,
+ pub data_type: DataType,
pub required: bool,
pub description: String,
pub number_exponent: i64,
@@ -50,6 +52,31 @@ pub struct GridPropertyDefinitionSlice {
pub struct_properties: Vec<GridPropertyDefinitionSlice>,
}
+#[derive(Deserialize, Debug)]
+pub enum DataType {
+ Bytes,
+ Boolean,
+ Number,
+ String,
+ Enum,
+ Struct,
+ LatLong,
+}
+
+impl Into<StateDataType> for DataType {
+ fn into(self) -> StateDataType {
+ match self {
+ DataType::Bytes => StateDataType::Bytes,
+ DataType::Boolean => StateDataType::Boolean,
+ DataType::Number => StateDataType::Number,
+ DataType::String => StateDataType::String,
+ DataType::Enum => StateDataType::Enum,
+ DataType::Struct => StateDataType::Struct,
+ DataType::LatLong => StateDataType::LatLong,
+ }
+ }
+}
+
pub fn display_schema(schema: &GridSchemaSlice) {
println!(
"Name: {:?}\n Description: {:?}\n Owner: {:?}\n Properties:",
@@ -296,7 +323,7 @@ fn parse_property_definition(property: &Mapping) -> Result<PropertyDefinition, C
};
property_definition = match data_type {
- DataType::Number => property_definition.with_number_exponent(
+ StateDataType::Number => property_definition.with_number_exponent(
parse_value_as_i32(property, "number_exponent")?.ok_or_else(|| {
CliError::InvalidYamlError(
"Missing `number_exponent` field for property definition with type NUMBER."
@@ -305,7 +332,7 @@ fn parse_property_definition(property: &Mapping) -> Result<PropertyDefinition, C
})?,
),
- DataType::Struct => {
+ StateDataType::Struct => {
let properties = parse_properties(
property
.get(&Value::String("struct_properties".to_string()))
@@ -315,7 +342,7 @@ fn parse_property_definition(property: &Mapping) -> Result<PropertyDefinition, C
)?;
property_definition.with_struct_properties(properties)
}
- DataType::Enum => property_definition.with_enum_options(
+ StateDataType::Enum => property_definition.with_enum_options(
parse_value_as_vec_string(property, "enum_options")?.ok_or_else(|| {
CliError::InvalidYamlError(
"Missing `enum_options` field for property definition with type ENUM."
