Skip to content

feat: generate a JSON schema for the config file - #2286

Closed
ChrisJr404 wants to merge 1 commit into
lycheeverse:masterfrom
ChrisJr404:config-schema
Closed

ChrisJr404 wants to merge 1 commit into
lycheeverse:masterfrom
ChrisJr404:config-schema

Conversation

@ChrisJr404

Copy link
Copy Markdown
Contributor

This adds a config-schema mode to --generate that prints a JSON schema for the config file, picking up #1382.

The schema is derived from the Config struct with schemars, so the field names and their descriptions come straight from the existing definitions and stay in sync automatically. With a TOML language server like Taplo you can then point lychee.toml at it for autocompletion and validation:

lychee --generate config-schema > lychee.schema.json
#:schema ./lychee.schema.json

A couple of implementation notes:

  • I kept schemars in lychee-bin only. Types that come from lychee-lib (and things like Duration or SecretString) are described via #[schemars(with = ...)] using their serialized form, so the lib crate is left untouched. Enums defined in the bin (StatsFormat, OutputMode, TlsVersion, FragmentMode) derive JsonSchema directly, so they expose their allowed values in the schema.
  • test_default_values scrapes the source for the doc-comment/#[arg]/field layout to verify documented defaults. I taught its regex to skip an optional #[schemars(...)] line so that convention still holds.

Happy to instead derive JsonSchema in lychee-lib for the lib-owned types (StatusCodeSelector and friends) if you would rather have richer schemas for those fields.

Add `lychee --generate config-schema`, which prints a JSON schema derived
from the config struct with schemars. Editors with a TOML language server
such as Taplo can use it for autocompletion and validation of lychee.toml.

Closes lycheeverse#1382
@mre

mre commented Oct 11, 2026

Copy link
Copy Markdown
Member

@ChrisJr404, #2299 just got merged, which contains your changes. I've added you as a co-author. Thanks for your contribution and for writing the initial draft of the schema config file generator. :)

@mre mre closed this Oct 11, 2026
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