Skip to content

Commit

Permalink
Extract json schema validation to mod json_schema_validator
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone committed Jul 24, 2024
1 parent fc9dab9 commit be0af28
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dsp-meta/src/api/convert/serde/json_schema_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ static DRAFT_SCHEMA: &str = include_str!("../../../../resources/schema-metadata-
pub enum SchemaVersion {
Draft
}
impl SchemaVersion {
fn schema_str(&self) -> &str {
match self {
Draft => DRAFT_SCHEMA
}
}
}

pub type Result<T> = core::result::Result<T, ValidationError>;
#[derive(Debug)]
Expand Down Expand Up @@ -49,7 +56,7 @@ fn load_path_as_json(path: &Path) -> Result<Value> {
}

fn load_json_schema(schema_version: SchemaVersion, scope: &mut Scope) -> Result<ScopedSchema> {
let schema_str = match schema_version { Draft => { DRAFT_SCHEMA } };
let schema_str = schema_version.schema_str();
let json = serde_json::from_str(schema_str).map_err(|e| NotAJsonFile(e))?;
scope.compile_and_return(json, false).map_err(|e| { SchemaError(e) })
}

0 comments on commit be0af28

Please sign in to comment.