Skip to content

feat: auto-generate JSON schema from Rust types#167

Merged
jdx merged 2 commits intomainfrom
feat/auto-generate-json-schema
Jan 19, 2026
Merged

feat: auto-generate JSON schema from Rust types#167
jdx merged 2 commits intomainfrom
feat/auto-generate-json-schema

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Jan 19, 2026

Summary

  • Uses schemars crate to derive JsonSchema from PitchforkToml configuration types
  • Adds hidden pitchfork schema CLI command to output the schema
  • Updates mise render task to regenerate schema automatically
  • Keeps schema in sync with Rust types - no manual maintenance needed

Changes

  • Added schemars dependency with indexmap2 feature for IndexMap support
  • Derived JsonSchema on all config types (PitchforkToml, PitchforkTomlDaemon, PitchforkTomlCron, CronRetrigger, PitchforkTomlAuto)
  • Added doc comments that become schema descriptions
  • Created src/cli/schema.rs with hidden schema command
  • Updated mise.toml render task to run pitchfork schema > docs/public/schema.json

Test plan

  • All 76 tests pass
  • pitchfork schema outputs valid JSON schema
  • Schema matches structure of previous manually-written schema

🤖 Generated with Claude Code


Note

Automates JSON Schema generation for pitchfork.toml and exposes it via a hidden CLI.

  • Adds schemars and derives JsonSchema on PitchforkToml, PitchforkTomlDaemon, PitchforkTomlCron, CronRetrigger, PitchforkTomlAuto (with doc comments as descriptions)
  • New hidden pitchfork schema subcommand that prints the generated schema (src/cli/schema.rs, wired in src/cli/mod.rs)
  • Updates mise.toml render task to run pitchfork schema > docs/public/schema.json
  • Replaces manual docs/public/schema.json with the generated schema; updates docs/cli/commands.json and pitchfork.usage.kdl to include the hidden schema command
  • Dependency and lockfile updates for schemars and transitive crates

Written by Cursor Bugbot for commit 40f809c. This will update automatically on new commits. Configure here.

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>
Copilot AI review requested due to automatic review settings January 19, 2026 15:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 schemars dependency and derived JsonSchema on all configuration types
  • Created hidden pitchfork schema CLI 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.

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://pitchfork.dev/schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "https://json-schema.org/draft/2020-12/schema",

Copilot uses AI. Check for mistakes.
impl Schema {
pub async fn run(&self) -> Result<()> {
let schema = schema_for!(PitchforkToml);
let json = serde_json::to_string_pretty(&schema).unwrap();
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
- 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>
@jdx jdx merged commit b5afb1c into main Jan 19, 2026
4 checks passed
@jdx jdx deleted the feat/auto-generate-json-schema branch January 19, 2026 15:53
@jdx jdx mentioned this pull request Jan 19, 2026
jdx added a commit that referenced this pull request Jan 19, 2026
## 🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants