CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Docs (push) Successful in 1m9s
CI / Deploy MCP (push) Successful in 5m21s
CI / Deploy Dashboard (push) Successful in 7m11s
CI / Deploy Agent (push) Successful in 9m19s
33 lines
1.2 KiB
Rust
33 lines
1.2 KiB
Rust
//! 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<String> {
|
|
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()
|
|
}
|