pub struct Schema { /* private fields */ }Expand description
Domain Entity: Schema
Represents a versioned schema definition for event validation. Schemas define the structure and validation rules for event payloads.
Domain Rules:
- Subject cannot be empty
- Version starts at 1 and increments
- Schema must be valid JSON
- Once registered, schemas are immutable
- New versions must respect compatibility mode
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn new(
subject: String,
version: u32,
schema_definition: JsonValue,
compatibility_mode: CompatibilityMode,
) -> Result<Self>
pub fn new( subject: String, version: u32, schema_definition: JsonValue, compatibility_mode: CompatibilityMode, ) -> Result<Self>
Create a new schema with validation
§Arguments
subject- The subject/topic this schema applies to (e.g., “order.placed”)version- Version number (must be >= 1)schema_definition- JSON Schema definitioncompatibility_mode- How to validate future schema changes
Sourcepub fn new_v1(
subject: String,
schema_definition: JsonValue,
compatibility_mode: CompatibilityMode,
) -> Result<Self>
pub fn new_v1( subject: String, schema_definition: JsonValue, compatibility_mode: CompatibilityMode, ) -> Result<Self>
Create first version of a schema
Sourcepub fn reconstruct(
id: Uuid,
subject: String,
version: u32,
schema_definition: JsonValue,
created_at: DateTime<Utc>,
description: Option<String>,
tags: Vec<String>,
compatibility_mode: CompatibilityMode,
) -> Self
pub fn reconstruct( id: Uuid, subject: String, version: u32, schema_definition: JsonValue, created_at: DateTime<Utc>, description: Option<String>, tags: Vec<String>, compatibility_mode: CompatibilityMode, ) -> Self
Reconstruct schema from storage (bypasses validation)
pub fn id(&self) -> Uuid
pub fn subject(&self) -> &str
pub fn version(&self) -> u32
pub fn schema_definition(&self) -> &JsonValue
pub fn created_at(&self) -> DateTime<Utc>
pub fn description(&self) -> Option<&str>
pub fn compatibility_mode(&self) -> CompatibilityMode
Sourcepub fn set_description(&mut self, description: String) -> Result<()>
pub fn set_description(&mut self, description: String) -> Result<()>
Add or update description
Sourcepub fn clear_description(&mut self)
pub fn clear_description(&mut self)
Clear description
Sourcepub fn remove_tag(&mut self, tag: &str) -> Result<()>
pub fn remove_tag(&mut self, tag: &str) -> Result<()>
Remove a tag
Sourcepub fn is_first_version(&self) -> bool
pub fn is_first_version(&self) -> bool
Check if this schema is the first version
Sourcepub fn applies_to(&self, subject: &str) -> bool
pub fn applies_to(&self, subject: &str) -> bool
Check if this schema applies to a subject
Sourcepub fn create_next_version(&self, new_schema: JsonValue) -> Result<Schema>
pub fn create_next_version(&self, new_schema: JsonValue) -> Result<Schema>
Create next version of schema
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Schema
impl<'de> Deserialize<'de> for Schema
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Schema
impl RefUnwindSafe for Schema
impl Send for Schema
impl Sync for Schema
impl Unpin for Schema
impl UnsafeUnpin for Schema
impl UnwindSafe for Schema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more