Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6444b300b3 | |||
| c529c8b8ea | |||
| 2f15ae3d41 |
17
src/lib.rs
17
src/lib.rs
@ -110,6 +110,23 @@ pub fn jspg_validate(schema_id: &str, instance: JsonB) -> JsonB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(not(test), pg_extern)]
|
||||||
|
pub fn jspg_schemas() -> JsonB {
|
||||||
|
let engine_opt = {
|
||||||
|
let lock = GLOBAL_JSPG.read().unwrap();
|
||||||
|
lock.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
match engine_opt {
|
||||||
|
Some(engine) => {
|
||||||
|
let schemas_json = serde_json::to_value(&engine.database.schemas)
|
||||||
|
.unwrap_or(serde_json::Value::Object(serde_json::Map::new()));
|
||||||
|
JsonB(schemas_json)
|
||||||
|
}
|
||||||
|
None => JsonB(serde_json::Value::Object(serde_json::Map::new())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(test), pg_extern)]
|
#[cfg_attr(not(test), pg_extern)]
|
||||||
pub fn jspg_stems() -> JsonB {
|
pub fn jspg_stems() -> JsonB {
|
||||||
let engine_opt = {
|
let engine_opt = {
|
||||||
|
|||||||
@ -49,6 +49,22 @@ fn test_library_api() {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// 3. Validate jspg_schemas
|
||||||
|
let schemas_drop = jspg_schemas();
|
||||||
|
assert_eq!(
|
||||||
|
schemas_drop.0,
|
||||||
|
json!({
|
||||||
|
"test_schema": {
|
||||||
|
"$id": "test_schema",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"name": { "type": "string" }
|
||||||
|
},
|
||||||
|
"required": ["name"]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
// 4. Validate Happy Path
|
// 4. Validate Happy Path
|
||||||
let happy_drop = jspg_validate("test_schema", JsonB(json!({"name": "Neo"})));
|
let happy_drop = jspg_validate("test_schema", JsonB(json!({"name": "Neo"})));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
Reference in New Issue
Block a user