Skip to main content

vtcode_config/
schema.rs

1use anyhow::{Context, Result};
2use schemars::{Schema, schema_for};
3
4use crate::loader::VTCodeConfig;
5
6/// Generate the JSON Schema describing the `vtcode.toml` configuration surface.
7pub fn vtcode_config_schema() -> Schema {
8    schema_for!(VTCodeConfig)
9}
10
11/// Render the configuration schema as a `serde_json::Value` for downstream tooling.
12pub fn vtcode_config_schema_json() -> Result<serde_json::Value> {
13    let schema = vtcode_config_schema();
14    serde_json::to_value(schema).context("failed to serialize vtcode-config schema to JSON value")
15}
16
17/// Render the configuration schema as a pretty-printed JSON string.
18pub fn vtcode_config_schema_pretty() -> Result<String> {
19    let value = vtcode_config_schema_json()?;
20    serde_json::to_string_pretty(&value).context("failed to serialize vtcode-config schema to pretty JSON string")
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26
27    #[test]
28    fn schema_exposes_prompt_cache_ttl_and_custom_capability() {
29        let schema = vtcode_config_schema_json().unwrap();
30        assert_eq!(schema.pointer("/$defs/PromptCacheTtl/enum"), Some(&serde_json::json!(["30m", "12h"])));
31        for definition in ["CustomProviderConfig", "CustomProviderProfileConfig"] {
32            assert!(
33                schema
34                    .pointer(&format!("/$defs/{definition}/properties/supports_prompt_cache_options"))
35                    .is_some()
36            );
37        }
38        assert!(
39            schema
40                .pointer("/$defs/OpenAIPromptCacheSettings/properties/prompt_cache_ttl")
41                .is_some()
42        );
43    }
44}