feat: auto-generate JSON schema from Rust types#167
Conversation
Replace the manually-maintained JSON schema with one derived from the Rust config types using schemars. This keeps the schema in sync with the code automatically. Changes: - Add schemars dependency with indexmap2 feature - Derive JsonSchema on PitchforkToml, PitchforkTomlDaemon, PitchforkTomlCron, CronRetrigger, and PitchforkTomlAuto - Add doc comments that become schema descriptions - Add hidden `pitchfork schema` CLI command for generation - Update mise render task to regenerate schema on build The schema is now generated as part of `mise run render` and will stay in sync with any changes to the config types. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR implements automatic JSON schema generation from Rust types using the schemars crate, eliminating the need for manual schema maintenance. The schema is now derived directly from the Rust configuration structs and can be regenerated automatically.
Changes:
- Added
schemarsdependency and derivedJsonSchemaon all configuration types - Created hidden
pitchfork schemaCLI command to output the generated schema - Updated the mise render task to automatically regenerate the schema file
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Cargo.toml | Added schemars dependency with indexmap2 feature |
| src/pitchfork_toml.rs | Derived JsonSchema on config types and added doc comments for schema descriptions |
| src/cli/schema.rs | New hidden CLI command that outputs the JSON schema |
| src/cli/mod.rs | Registered the schema command in the CLI router |
| pitchfork.usage.kdl | Added schema command definition (hidden) |
| mise.toml | Updated render task to regenerate schema automatically |
| docs/public/schema.json | Auto-generated schema replacing manually written version |
| docs/cli/commands.json | Auto-generated CLI documentation for schema command |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
docs/public/schema.json
Outdated
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "$id": "https://pitchfork.dev/schema.json", | ||
| "$schema": "http://json-schema.org/draft-07/schema#", |
There was a problem hiding this comment.
The schema is using an older JSON Schema draft (draft-07) while the previous version used draft 2020-12. Consider if this downgrade is intentional. If the schemars crate supports draft 2020-12, it would be preferable to use the newer standard for better compatibility with modern tooling.
| "$schema": "http://json-schema.org/draft-07/schema#", | |
| "$schema": "https://json-schema.org/draft/2020-12/schema", |
| impl Schema { | ||
| pub async fn run(&self) -> Result<()> { | ||
| let schema = schema_for!(PitchforkToml); | ||
| let json = serde_json::to_string_pretty(&schema).unwrap(); |
There was a problem hiding this comment.
The .unwrap() call can panic if serialization fails. Consider using .into_diagnostic()? to provide better error handling consistent with the function's Result<()> return type.
- Update schemars from 0.8 to 1.x - Update example attribute syntax for v1 API - Schema now uses JSON Schema 2020-12 draft Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
## 🤖 New release * `pitchfork-cli`: 1.0.2 -> 1.1.0 <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [1.1.0](v1.0.2...v1.1.0) - 2026-01-19 ### Added - add file watching to auto-restart daemons ([#165](#165)) - support boolean values for retry configuration ([#170](#170)) - disable web UI by default ([#172](#172)) - auto-generate JSON schema from Rust types ([#167](#167)) ### Fixed - improve cron watcher granularity for sub-minute schedules ([#163](#163)) - improve log file position tracking accuracy ([#164](#164)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Releases `pitchfork-cli` v1.1.0 and syncs version across `Cargo.toml`, `Cargo.lock`, `docs/cli/*`, and `pitchfork.usage.kdl`. > > - **Added**: file watching to auto-restart daemons; boolean support for retry config; web UI disabled by default; JSON schema generation from Rust types > - **Fixed**: improved cron watcher granularity (sub-minute); more accurate log file position tracking > - Updated `CHANGELOG.md` with 1.1.0 notes > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 2e6d4c6. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Summary
pitchfork schemaCLI command to output the schemaChanges
indexmap2feature for IndexMap supportJsonSchemaon all config types (PitchforkToml, PitchforkTomlDaemon, PitchforkTomlCron, CronRetrigger, PitchforkTomlAuto)src/cli/schema.rswith hidden schema commandmise.tomlrender task to runpitchfork schema > docs/public/schema.jsonTest plan
pitchfork schemaoutputs valid JSON schema🤖 Generated with Claude Code
Note
Automates JSON Schema generation for
pitchfork.tomland exposes it via a hidden CLI.schemarsand derivesJsonSchemaonPitchforkToml,PitchforkTomlDaemon,PitchforkTomlCron,CronRetrigger,PitchforkTomlAuto(with doc comments as descriptions)pitchfork schemasubcommand that prints the generated schema (src/cli/schema.rs, wired insrc/cli/mod.rs)mise.tomlrender task to runpitchfork schema > docs/public/schema.jsondocs/public/schema.jsonwith the generated schema; updatesdocs/cli/commands.jsonandpitchfork.usage.kdlto include the hiddenschemacommandschemarsand transitive cratesWritten by Cursor Bugbot for commit 40f809c. This will update automatically on new commits. Configure here.