Skip to main content

DataModel

Struct DataModel 

Source
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

Source

pub fn new(name: Option<String>, config: Option<FrontMatter>) -> Self

Source

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.

Source

pub fn json_schema( &self, obj_name: Option<String>, openai: bool, ) -> Result<String, Box<dyn Error>>

Source

pub fn json_schema_all( &self, path: PathBuf, openai: bool, ) -> Result<(), Box<dyn Error>>

Source

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. If None, 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).
Source

pub fn internal_schema(&self) -> String

Source

pub fn from_internal_schema(path: &Path) -> Result<Self, Box<dyn Error>>

Source

pub fn sort_attrs(&mut self)

Sort the attributes of all objects by required

Source

pub fn convert_to( &mut self, template: &Templates, config: Option<&HashMap<String, String>>, ) -> Result<String, Error>

Source

pub fn merge(&mut self, other: &Self)

Source

pub fn from_markdown(path: &Path) -> Result<Self, Validator>

Parse a markdown file and create a data model

  • path - Path to the markdown file
§Examples
use std::path::Path;
use mdmodels_core::datamodel::DataModel;

let path = Path::new("tests/data/model.md");
let model = DataModel::from_markdown(path);
§Returns

A data model

Source

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

Source

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

Source

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

Source

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 Clone for DataModel

Source§

fn clone(&self) -> DataModel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DataModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DataModel

Source§

fn default() -> DataModel

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for DataModel

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<DataModel> for LinkML

Implements conversion from DataModel to LinkML schema format.

Source§

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.

Source§

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 PartialEq for DataModel

Source§

fn eq(&self, other: &DataModel) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for DataModel

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<DataModel> for ModelType

Source§

fn try_from(model: DataModel) -> Result<Self, Self::Error>

Creates a ModelType from a DataModel.

Source§

type Error = Box<dyn Error>

The type returned in the event of a conversion error.
Source§

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.

Source§

type Error = Box<dyn Error>

The type returned in the event of a conversion error.
Source§

fn try_from(schema_obj: SchemaObject) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for DataModel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,