//! What the schema tests share: the vendored schemas and the CycloneDX //! validation. #![allow(clippy::expect_used, clippy::unwrap_used, dead_code)] /// The vendored schema `name` (in `schemas/`). pub fn schema(name: &str) -> serde_json::Value { let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) .join("schemas") .join(name); serde_json::from_str(&std::fs::read_to_string(path).unwrap()).unwrap() } /// The errors of `doc` against CycloneDX 1.6 (with the SPDX and JSF schemas /// it refers to). pub fn cyclonedx_errors(doc: &serde_json::Value) -> Vec { let validator = jsonschema::options() .with_resource( "http://cyclonedx.org/schema/spdx.schema.json", jsonschema::Resource::from_contents(schema("spdx.schema.json")).unwrap(), ) .with_resource( "http://cyclonedx.org/schema/jsf-0.82.schema.json", jsonschema::Resource::from_contents(schema("jsf-0.82.schema.json")).unwrap(), ) .build(&schema("bom-1.6.schema.json")) .unwrap(); validator .iter_errors(doc) .map(|e| format!("{} at {}", e, e.instance_path)) .collect() }