Skip to content

Commit

Permalink
Merge pull request #15 from FAIRChemistry/update-pulldown-cmark-dep
Browse files Browse the repository at this point in the history
Update pulldown-cmark dep and add lines/ranges for validation errors
  • Loading branch information
JR-1991 authored Dec 19, 2024
2 parents 7196fd0 + f9cc45b commit d4da04e
Show file tree
Hide file tree
Showing 11 changed files with 532 additions and 63 deletions.
13 changes: 10 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
serde = { version = "1.0.198", features = ["derive"] }
pulldown-cmark = "0.8.0"
pulldown-cmark = "0.12.2"
serde_json = { "version" = "1.0.116", features = ["preserve_order"] }
regex = "1.10.4"
serde_with = "3.8.0"
Expand Down
15 changes: 14 additions & 1 deletion src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
*/

use crate::xmltype::XMLType;
use crate::{markdown::parser::Position, xmltype::XMLType};
use serde::{de::Visitor, Deserialize, Serialize};
use std::{error::Error, fmt, str::FromStr};

Expand Down Expand Up @@ -57,6 +57,9 @@ pub struct Attribute {
pub xml: Option<XMLType>,
/// Is an enumeration or not
pub is_enum: bool,
/// The line number of the attribute
#[serde(skip_serializing)]
pub position: Option<Position>,
}

impl Attribute {
Expand All @@ -79,6 +82,7 @@ impl Attribute {
xml: Some(XMLType::from_str(name.as_str()).unwrap()),
default: None,
is_enum: false,
position: None,
}
}

Expand All @@ -91,6 +95,15 @@ impl Attribute {
self.docstring = docstring;
}

/// Sets the line number of the attribute.
///
/// # Arguments
///
/// * `position` - The position to set.
pub fn set_position(&mut self, position: Position) {
self.position = Some(position);
}

/// Adds an option to the attribute.
///
/// # Arguments
Expand Down
10 changes: 9 additions & 1 deletion src/datamodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ impl DataModel {
// Get the JSON schema for an object
//
// * `obj_name` - Name of the object
// * `openai` - Whether to remove options from the schema properties. OpenAI does not support options.
//
// # Panics
//
// If no objects are found in the markdown file
// If the object is not found in the markdown file
//
Expand Down Expand Up @@ -304,6 +304,7 @@ impl DataModel {
/// ```
/// # Returns
/// A data model
#[allow(clippy::result_large_err)]
pub fn from_markdown(path: &Path) -> Result<Self, Validator> {
let content = fs::read_to_string(path).expect("Could not read file");
parse_markdown(&content)
Expand All @@ -326,6 +327,7 @@ impl DataModel {
/// ```
/// # Returns
/// A data model
#[allow(clippy::result_large_err)]
pub fn from_markdown_string(content: &str) -> Result<Self, Validator> {
parse_markdown(content)
}
Expand Down Expand Up @@ -359,6 +361,7 @@ mod tests {
xml: None,
default: None,
is_enum: false,
position: None,
});

let mut obj2 = Object::new("Object2".to_string(), None);
Expand All @@ -374,18 +377,21 @@ mod tests {
xml: None,
default: None,
is_enum: false,
position: None,
});

let enm1 = Enumeration {
name: "Enum1".to_string(),
mappings: BTreeMap::from([("key1".to_string(), "value1".to_string())]),
docstring: "".to_string(),
position: None,
};

let enm2 = Enumeration {
name: "Enum2".to_string(),
mappings: BTreeMap::from([("key2".to_string(), "value2".to_string())]),
docstring: "".to_string(),
position: None,
};

model1.objects.push(obj1);
Expand Down Expand Up @@ -422,6 +428,7 @@ mod tests {
xml: None,
default: Some(DataType::String("".to_string())),
is_enum: false,
position: None,
});

obj.add_attribute(crate::attribute::Attribute {
Expand All @@ -436,6 +443,7 @@ mod tests {
xml: None,
default: None,
is_enum: false,
position: None,
});

model.objects.push(obj);
Expand Down
2 changes: 2 additions & 0 deletions src/json/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ mod tests {
default: None,
xml: None,
is_enum: false,
position: None,
};

let property: schema::Property =
Expand Down Expand Up @@ -563,6 +564,7 @@ mod tests {
default: None,
xml: None,
is_enum: false,
position: None,
};

let property: schema::Property =
Expand Down
Loading

0 comments on commit d4da04e

Please sign in to comment.