Skip to content

Commit

Permalink
H-3755: Improve validation structure for entity properties (#5850)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann authored Dec 11, 2024
1 parent b0bbac4 commit fed76f3
Show file tree
Hide file tree
Showing 21 changed files with 1,911 additions and 645 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::{schema::data_type::constraint::ValueConstraints, url::VersionedUrl};

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(target_arch = "wasm32", derive(tsify::Tsify))]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(rename_all = "kebab-case")]
pub enum JsonSchemaValueType {
Null,
Expand Down
2 changes: 1 addition & 1 deletion libs/@blockprotocol/type-system/rust/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ pub use self::{
one_of::{OneOfSchema, OneOfSchemaValidationError, OneOfSchemaValidator},
property_type::{
PropertyType, PropertyTypeReference, PropertyTypeValidationError, PropertyTypeValidator,
PropertyValueSchema, PropertyValues,
PropertyValueSchema, PropertyValueType, PropertyValues,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ pub enum PropertyValues {
ArrayOfPropertyValues(PropertyValueArray<OneOfSchema<PropertyValues>>),
}

#[derive(Debug, serde::Serialize)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[serde(rename_all = "kebab-case")]
pub enum PropertyValueType {
Value,
Array,
Object,
}

impl PropertyValues {
#[must_use]
fn data_type_references(&self) -> Vec<&DataTypeReference> {
Expand Down Expand Up @@ -103,6 +112,15 @@ impl PropertyValues {
.collect(),
}
}

#[must_use]
pub const fn property_value_type(&self) -> PropertyValueType {
match self {
Self::DataTypeReference(_) => PropertyValueType::Value,
Self::PropertyTypeObject(_) => PropertyValueType::Object,
Self::ArrayOfPropertyValues(_) => PropertyValueType::Array,
}
}
}

pub trait PropertyValueSchema {
Expand Down
Loading

0 comments on commit fed76f3

Please sign in to comment.