Example project of parsing yaml files into Rust types via serde and validating the yaml documents in VSCode (requires the yaml extension) by generating JSON schema to lint the YAML in the build.rs script.
- Rust types are defined in the ./types crate. The types derive
serde::Deserializeandschemars::JsonSchema. - The program
./program/build.rsfile generates a JSON Schema from the type into./program/schemas - The
.vscode/settings.jsonfile references theprogram/data/example.yamldata file and the schema to validate against - VSCode will now validate the
example.yamlfile automatically when edited - The program to load the yaml file into a Rust struct can be called via
cargo run program
- Generate the
.vscode/settings.jsonconfig for 'yaml.schemas' inside the build.rs script - Update
program/build.rsto read Rust types generically from a directory (parse usingsyn) or referenced from the yaml file - Create git hooks to validate the yaml based on the generated JSON Schema or Rust types