use crate::{
rest_api::resources::paging::v1::Paging,
schema::store::{PropertyDefinition, Schema},
};
#[derive(Debug, Serialize, Deserialize)]
pub struct SchemaSlice {
pub name: String,
pub description: String,
pub owner: String,
pub properties: Vec<PropertyDefinitionSlice>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub service_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_updated: Option<i64>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SchemaListSlice {
pub data: Vec<SchemaSlice>,
pub paging: Paging,
}
impl From<Schema> for SchemaSlice {
fn from(schema: Schema) -> Self {
Self {
name: schema.name.clone(),
description: schema.description.clone(),
owner: schema.owner.clone(),
properties: schema
.properties
.into_iter()
.map(PropertyDefinitionSlice::from)
.collect(),
service_id: schema.service_id,
last_updated: schema.last_updated,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PropertyDefinitionSlice {
pub name: String,
pub schema_name: String,
pub data_type: String,
pub required: bool,
pub description: String,
pub number_exponent: i64,
pub enum_options: Vec<String>,
pub struct_properties: Vec<PropertyDefinitionSlice>,
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub service_id: Option<String>,
}
impl From<PropertyDefinition> for PropertyDefinitionSlice {
fn from(definition: PropertyDefinition) -> Self {
Self {
name: definition.name.clone(),
schema_name: definition.schema_name.clone(),
data_type: definition.data_type.clone(),
required: definition.required,
description: definition.description.clone(),
number_exponent: definition.number_exponent,
enum_options: definition.enum_options.clone(),
struct_properties: definition
.struct_properties
.into_iter()
.map(PropertyDefinitionSlice::from)
.collect(),
service_id: definition.service_id,
}
}
}