Repository navigation
feat: generate a JSON schema for the config file - #2286
Closed
ChrisJr404 wants to merge 1 commit into
Closed
ChrisJr404 wants to merge 1 commit into
ChrisJr404 wants to merge 1 commit into
Conversation
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
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. :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a
config-schemamode to--generatethat prints a JSON schema for the config file, picking up #1382.The schema is derived from the
Configstruct withschemars, 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 pointlychee.tomlat it for autocompletion and validation:lychee --generate config-schema > lychee.schema.json#:schema ./lychee.schema.jsonA couple of implementation notes:
schemarsinlychee-binonly. Types that come fromlychee-lib(and things likeDurationorSecretString) 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) deriveJsonSchemadirectly, so they expose their allowed values in the schema.test_default_valuesscrapes 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
JsonSchemainlychee-libfor the lib-owned types (StatusCodeSelectorand friends) if you would rather have richer schemas for those fields.