pub mod checks;
pub mod corpus;
pub mod crs;
pub mod source;
pub mod spatial;
pub mod verify;
pub mod wkb;
#[cfg(feature = "capi")]
pub mod capi;
#[cfg(feature = "cli")]
pub mod cli;
#[cfg(feature = "python")]
mod python;
#[cfg(feature = "wasm")]
pub mod wasm;
use checks::{Options, Report, Schemas};
pub fn validate(target: &str, max_rows: Option<usize>) -> anyhow::Result<Report> {
let schemas = Schemas::load()?;
let options = Options { max_rows };
#[cfg(feature = "remote")]
if source::is_remote(target) {
let url = url::Url::parse(target)?;
let opts = source::RemoteOptions {
s3_region: None,
extra: Vec::new(),
};
let src = source::open_remote(&url, &opts)?;
return checks::run(&src, &schemas, &options);
}
let src = source::Local(std::path::PathBuf::from(target));
checks::run(&src, &schemas, &options)
}
pub fn validate_bytes(
name: &str,
bytes: Vec<u8>,
max_rows: Option<usize>,
) -> anyhow::Result<Report> {
let schemas = Schemas::load()?;
let src = source::InMemory {
name: name.to_string(),
bytes: bytes::Bytes::from(bytes),
};
checks::run(&src, &schemas, &Options { max_rows })
}
#[cfg(test)]
mod tests {
#[test]
fn report_matches_its_schema() {
let schema: serde_json::Value =
serde_json::from_str(include_str!("../schemas/report.schema.json")).unwrap();
let validator = jsonschema::validator_for(&schema).unwrap();
let path = "corpus/data/bbox/bbox-present.parquet";
if !std::path::Path::new(path).exists() {
eprintln!("skipped: {path} not present");
return;
}
let report = super::validate(path, None).unwrap();
let value = serde_json::to_value(&report).unwrap();
let errors: Vec<String> = validator
.iter_errors(&value)
.map(|e| e.to_string())
.collect();
assert!(errors.is_empty(), "{errors:?}");
assert_eq!(value["report_version"], 1);
}
}