ito_config/config/
schema.rs

1//! JSON schema generation for Ito config.
2
3use schemars::schema_for;
4use serde_json::Value;
5
6use super::types::ItoConfig;
7
8/// Generate the JSON schema (as JSON) for [`ItoConfig`].
9pub fn config_schema_json() -> Value {
10    let schema = schema_for!(ItoConfig);
11    serde_json::to_value(&schema).expect("config schema should serialize to json")
12}
13
14/// Generate the JSON schema (pretty-printed) for [`ItoConfig`].
15pub fn config_schema_pretty_json() -> String {
16    serde_json::to_string_pretty(&config_schema_json()).unwrap_or_else(|_| "{}".to_string())
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    #[test]
24    fn schema_contains_expected_sections() {
25        let v = config_schema_json();
26        let props = v
27            .get("properties")
28            .and_then(|p| p.as_object())
29            .or_else(|| {
30                v.get("schema")
31                    .and_then(|s| s.get("properties"))
32                    .and_then(|p| p.as_object())
33            })
34            .expect("schema properties");
35
36        assert!(props.contains_key("projectPath"));
37        assert!(props.contains_key("harnesses"));
38        assert!(props.contains_key("cache"));
39        assert!(props.contains_key("defaults"));
40        assert!(props.contains_key("$schema"));
41    }
42}