Skip to content

Commit 964c8e3

Browse files
committed
Revert "Json schema import (#29)"
This reverts commit 8c375d3.
1 parent abec889 commit 964c8e3

34 files changed

Lines changed: 397 additions & 2842 deletions

Cargo.lock

Lines changed: 36 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mdmodels"
33
authors = ["Jan Range <jan.range@simtech.uni-stuttgart.de>"]
44
description = "A tool to generate models, code and schemas from markdown files"
5-
version = "0.2.3"
5+
version = "0.2.4"
66
edition = "2021"
77
license = "MIT"
88
repository = "https://github.com/FAIRChemistry/md-models"
@@ -44,7 +44,6 @@ petgraph = { version = "0.7.1", features = ["serde"] }
4444
schemars = { version = "0.8.22", features = ["derive_json_schema"] }
4545
json-patch = "4.0.0"
4646
thiserror = "2.0.12"
47-
variantly = "0.4.0"
4847

4948
[features]
5049
default = ["openai"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "maturin"
44

55
[project]
66
name = "mdmodels_core"
7-
version = "0.2.3"
7+
version = "0.2.4"
88
description = "A tool to generate models, code and schemas from markdown files"
99
requires-python = ">=3.8"
1010
classifiers = [

src/bin/cli.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,7 @@ fn query_llm(args: ExtractArgs) -> Result<(), Box<dyn Error>> {
321321
fn convert(args: ConvertArgs) -> Result<(), Box<dyn Error>> {
322322
// Parse the markdown model.
323323
let path = resolve_input_path(&args.input);
324-
325-
let mut model = if is_json_schema(&path)? {
326-
DataModel::from_json_schema(&path)?
327-
} else {
328-
DataModel::from_markdown(&path)?
329-
};
324+
let mut model = DataModel::from_markdown(&path)?;
330325

331326
// Special case JSON Schema all
332327
if let Templates::JsonSchemaAll = args.template {
@@ -341,9 +336,7 @@ fn convert(args: ConvertArgs) -> Result<(), Box<dyn Error>> {
341336
.map(|s| (s.clone(), "true".to_string()))
342337
.collect();
343338
let rendered = match args.template {
344-
Templates::JsonSchema => {
345-
model.json_schema(args.root, args.options.contains(&"openai".to_string()))?
346-
}
339+
Templates::JsonSchema => model.json_schema(args.root, false)?,
347340
Templates::Linkml => serialize_linkml(model, args.output.as_ref())?,
348341
_ => render_jinja_template(&args.template, &mut model, Some(&config))?,
349342
};
@@ -361,25 +354,6 @@ fn convert(args: ConvertArgs) -> Result<(), Box<dyn Error>> {
361354
Ok(())
362355
}
363356

364-
/// Checks if the input is a JSON Schema.
365-
///
366-
/// # Arguments
367-
///
368-
/// * `path` - The path to the input file.
369-
///
370-
/// # Returns
371-
///
372-
/// True if the input is a JSON Schema, false otherwise.
373-
fn is_json_schema(path: &PathBuf) -> Result<bool, Box<dyn Error>> {
374-
let content = std::fs::read_to_string(path)?;
375-
let parsed = serde_json::from_str::<serde_json::Value>(&content);
376-
377-
match parsed {
378-
Ok(value) => Ok(value.is_object()),
379-
Err(_) => Ok(false),
380-
}
381-
}
382-
383357
/// Resolves the input path based on the InputType.
384358
///
385359
/// If the input is a remote URL, it fetches the content and saves it to a temporary file.

src/bindings/wasm.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use crate::datamodel::DataModel;
2525
use crate::exporters::Templates;
2626
use crate::json::export::to_json_schema;
27-
use crate::json::schema::SchemaObject;
2827
use crate::validation::Validator;
2928
use wasm_bindgen::prelude::*;
3029

@@ -72,28 +71,6 @@ pub fn convert_to(markdown_content: &str, template: Templates) -> Result<String,
7271
.map_err(|e| JsValue::from_str(&format!("Error converting markdown content: {}", e)))
7372
}
7473

75-
/// Parses the given JSON schema string into a `DataModel`.
76-
///
77-
/// # Arguments
78-
///
79-
/// * `json_schema` - A string slice that holds the JSON schema to be parsed.
80-
///
81-
/// # Returns
82-
///
83-
/// A `String` or an error `JsError`.
84-
#[wasm_bindgen]
85-
pub fn from_json_schema(json_schema: JsValue) -> Result<String, JsError> {
86-
let schema: SchemaObject = serde_wasm_bindgen::from_value(json_schema)
87-
.map_err(|e| JsError::new(&format!("Error deserializing JSON schema: {}", e)))?;
88-
89-
let mut model = DataModel::from_json_schema_object(schema)
90-
.map_err(|e| JsError::new(&format!("Error parsing JSON schema: {}", e)))?;
91-
92-
model
93-
.convert_to(&Templates::Markdown, None)
94-
.map_err(|e| JsError::new(&format!("Error converting markdown content: {}", e)))
95-
}
96-
9774
/// Returns the JSON schema for the given markdown content.
9875
///
9976
/// # Arguments

src/datamodel.rs

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@ use std::{error::Error, fs, path::Path};
2828
use log::error;
2929
use serde::{Deserialize, Serialize};
3030

31-
use crate::error::DataModelError;
3231
use crate::exporters::{render_jinja_template, Templates};
3332
use crate::json::export::to_json_schema;
34-
use crate::json::schema::SchemaObject;
3533
use crate::json::validation::{validate_json, ValidationError};
3634
use crate::linkml::export::serialize_linkml;
3735
use crate::markdown::frontmatter::FrontMatter;
38-
use crate::markdown::parser::{parse_markdown, validate_model};
36+
use crate::markdown::parser::parse_markdown;
3937
use crate::object::{Enumeration, Object};
4038
use crate::validation::Validator;
4139
use colored::Colorize;
@@ -367,63 +365,6 @@ impl DataModel {
367365
pub fn from_markdown_string(content: &str) -> Result<Self, Validator> {
368366
parse_markdown(content, None)
369367
}
370-
371-
/// Parse a JSON schema file and create a data model
372-
///
373-
/// * `path` - Path to the JSON schema file
374-
///
375-
/// # Returns
376-
/// A data model
377-
#[allow(clippy::result_large_err)]
378-
pub fn from_json_schema(path: &Path) -> Result<Self, DataModelError> {
379-
let content = fs::read_to_string(path)?;
380-
let schema: SchemaObject = serde_json::from_str(&content)?;
381-
let model: DataModel = schema
382-
.try_into()
383-
.expect("Could not convert schema to data model");
384-
385-
// Validate the data model
386-
validate_model(&model).map_err(DataModelError::ValidationError)?;
387-
388-
Ok(model)
389-
}
390-
391-
/// Parse a JSON schema string and create a data model
392-
///
393-
/// * `content` - The JSON schema string
394-
///
395-
/// # Returns
396-
/// A data model
397-
#[allow(clippy::result_large_err)]
398-
pub fn from_json_schema_string(content: &str) -> Result<Self, DataModelError> {
399-
let schema: SchemaObject = serde_json::from_str(content)?;
400-
let model: DataModel = schema
401-
.try_into()
402-
.expect("Could not convert schema to data model");
403-
404-
// Validate the data model
405-
validate_model(&model).map_err(DataModelError::ValidationError)?;
406-
407-
Ok(model)
408-
}
409-
410-
/// Parse a JSON schema object and create a data model
411-
///
412-
/// * `schema` - The JSON schema object
413-
///
414-
/// # Returns
415-
/// A data model
416-
#[allow(clippy::result_large_err)]
417-
pub fn from_json_schema_object(schema: SchemaObject) -> Result<Self, DataModelError> {
418-
let model: DataModel = schema
419-
.try_into()
420-
.expect("Could not convert schema to data model");
421-
422-
// Validate the data model
423-
validate_model(&model).map_err(DataModelError::ValidationError)?;
424-
425-
Ok(model)
426-
}
427368
}
428369

429370
#[cfg(test)]

src/error.rs

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)