pub struct DataModel {
pub name: Option<String>,
pub objects: Vec<Object>,
pub enums: Vec<Enumeration>,
pub config: Option<FrontMatter>,
}Fields§
§name: Option<String>§objects: Vec<Object>§enums: Vec<Enumeration>§config: Option<FrontMatter>Implementations§
Source§impl DataModel
impl DataModel
pub fn new(name: Option<String>, config: Option<FrontMatter>) -> Self
Sourcepub fn validate_json(
&self,
path: &Path,
root: Option<String>,
) -> Result<Vec<ValidationError>, Box<dyn Error>>
pub fn validate_json( &self, path: &Path, root: Option<String>, ) -> Result<Vec<ValidationError>, Box<dyn Error>>
Validates a dataset against the data model.
This function takes the path to a dataset and validates it against the current data model. It returns a vector of validation errors if any validation issues are found, or an empty vector if the validation is successful.
§Arguments
path- A reference to the path of the dataset to validate.root- An optional root path for the schema. Will use the first object if not provided.
§Returns
A Result containing a vector of ValidationError if validation fails,
or an empty vector if successful.
pub fn json_schema( &self, obj_name: Option<String>, openai: bool, ) -> Result<String, Box<dyn Error>>
pub fn json_schema_all( &self, path: PathBuf, openai: bool, ) -> Result<(), Box<dyn Error>>
Sourcepub fn json_ld_header(
&self,
root: Option<&str>,
) -> Result<JsonLdHeader, Box<dyn Error>>
pub fn json_ld_header( &self, root: Option<&str>, ) -> Result<JsonLdHeader, Box<dyn Error>>
Generates a JSON-LD header (JsonLdHeader) for the data model, suitable for use in JSON-LD serialization.
This method constructs a JsonLdHeader using the model’s configuration and optionally a specified root object.
The header contains the appropriate JSON-LD @context, @id, and @type for the model or selected object.
§Arguments
root- Optional. The name of the root object to use. IfNone, the first object in the model is used.
§Returns
Ok(JsonLdHeader)with the generated JSON-LD header if successful.Err(Box<dyn Error>)if the generation fails (for example, if the root is not found).
pub fn internal_schema(&self) -> String
pub fn from_internal_schema(path: &Path) -> Result<Self, Box<dyn Error>>
Sourcepub fn sort_attrs(&mut self)
pub fn sort_attrs(&mut self)
Sort the attributes of all objects by required
pub fn convert_to( &mut self, template: &Templates, config: Option<&HashMap<String, String>>, ) -> Result<String, Error>
pub fn merge(&mut self, other: &Self)
Sourcepub fn from_markdown(path: &Path) -> Result<Self, Validator>
pub fn from_markdown(path: &Path) -> Result<Self, Validator>
Sourcepub fn from_markdown_string(content: &str) -> Result<Self, Validator>
pub fn from_markdown_string(content: &str) -> Result<Self, Validator>
Parse a markdown file and create a data model
path- Path to the markdown file
§Examples
use std::path::Path;
use std::fs;
use mdmodels_core::datamodel::DataModel;
let path = Path::new("tests/data/model.md");
let content = fs::read_to_string(path).unwrap();
let model = DataModel::from_markdown_string(content.as_str());§Returns
A data model
Sourcepub fn from_json_schema(path: &Path) -> Result<Self, DataModelError>
pub fn from_json_schema(path: &Path) -> Result<Self, DataModelError>
Parse a JSON schema file and create a data model
path- Path to the JSON schema file
§Returns
A data model
Sourcepub fn from_json_schema_string(content: &str) -> Result<Self, DataModelError>
pub fn from_json_schema_string(content: &str) -> Result<Self, DataModelError>
Parse a JSON schema string and create a data model
content- The JSON schema string
§Returns
A data model
Sourcepub fn from_json_schema_object(
schema: SchemaObject,
) -> Result<Self, DataModelError>
pub fn from_json_schema_object( schema: SchemaObject, ) -> Result<Self, DataModelError>
Parse a JSON schema object and create a data model
schema- The JSON schema object
§Returns
A data model
Trait Implementations§
Source§impl<'de> Deserialize<'de> for DataModel
impl<'de> Deserialize<'de> for DataModel
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>,
Source§impl From<DataModel> for LinkML
Implements conversion from DataModel to LinkML schema format.
impl From<DataModel> for LinkML
Implements conversion from DataModel to LinkML schema format.
Source§fn from(model: DataModel) -> Self
fn from(model: DataModel) -> Self
Converts a DataModel instance into a LinkML schema.
This conversion process handles:
- Basic schema configuration including ID, prefixes, and name
- Class definitions and their attributes
- Global slots (shared attributes across classes)
- Enumeration definitions
- Import declarations
- Default type configurations
The conversion maintains the hierarchical structure of the data model while adapting it to LinkML’s schema format requirements.
Source§impl From<LinkML> for DataModel
Implements conversion from LinkML schema to DataModel.
impl From<LinkML> for DataModel
Implements conversion from LinkML schema to DataModel.
Source§fn from(linkml: LinkML) -> Self
fn from(linkml: LinkML) -> Self
Converts a LinkML schema into the internal DataModel format.
This conversion handles:
- Schema metadata through FrontMatter configuration
- Classes and their attributes
- Global slots/attributes
- Enumerations
The conversion preserves:
- Prefixes and namespace information
- Class hierarchies and relationships
- Attribute definitions and constraints
- Enumeration values and meanings
Source§impl TryFrom<SchemaObject> for DataModel
Converts a JSON Schema object to a DataModel
impl TryFrom<SchemaObject> for DataModel
Converts a JSON Schema object to a DataModel
This implementation handles the conversion of the root schema object and all its definitions to the corresponding DataModel structure, including objects and enumerations.