|
https://www.schemastore.org/ provide schemas for auto completion of json/yaml/toml files. |
Replies: 2 comments 1 reply
|
Yes, and it's actually straightforward because tokei already uses The cleanest approach is # Cargo.toml
[dependencies]
schemars = { version = "0.8", features = ["preserve_order"] }// in src/config.rs (or wherever Config is defined)
use schemars::JsonSchema;
#[derive(Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct Config {
pub columns: Option<Vec<String>>,
pub hidden: Option<Vec<String>>,
pub languages: Option<HashMap<String, Language>>,
pub output: Option<Output>,
// ...existing fields
}Then add a small CLI command or a fn write_schema() -> std::io::Result<()> {
let schema = schemars::schema_for!(Config);
std::fs::write("docs/tokei.schema.json", serde_json::to_string_pretty(&schema)?)
}Two practical notes:
Once
Net: one |
|
Self-correction after re-reading
Revised patch: // src/config.rs
use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; // add Serialize
#[derive(Debug, Default, Serialize, Deserialize, JsonSchema)]
pub struct Config { /* unchanged */ }# Cargo.toml
schemars = { version = "0.8", features = ["preserve_order"] }Note the deliberate choice not to add |
Self-correction after re-reading
src/config.rs. Two corrections to my previous reply:Configis NOT markeddeny_unknown_fields. Current derive is just#[derive(Debug, Default, Deserialize)](noSerialize, nodeny_unknown_fields). My comment "make sure to keepdeny_unknown_fieldswhen you addJsonSchema" was wrong — there is none to keep, and the derived schema will reflect whatever the deserializer actually accepts (which today is permissive — unknown keys are silently dropped).Configis re-exported from the crate root, so the derive lives on the re-exported type, not ontokei::config::Config:That doesn't change the answer (…