Repository navigation
Auto-generate JSON schema from Rust types - #2299
Conversation
c24bb1a to
d6a3686
Compare
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 #1382
48043f8 to
71613b3
Compare
|
While working on this feature, I noticed that lychee trims surrounding whitespace from basic-auth selectors. For example: basic_auth = ["example.com user:password "]The trailing space is silently removed, even though it could be part of the password. That's what lychee did before this PR as well, so it's not something introduced by this PR. Other tools generally preserve spaces in the supplied credentials rather than trim or reject them: curl, Python Requests, and HTTPie. RFC 7617 also permits ordinary spaces in Basic-auth credentials, though it forbids control characters. For this PR, I've made the schema match our existing parser. That's because rejecting whitespace only in the schema would mean that editor validation rejects configurations that lychee accepts at the moment. And I've added a comment explaining that choice. I think we should revisit the trimming in the near future. Ideally, we'd preserve credential content rather than silently change it, but that requires a decision on how we will handle our combined |
Add schema tests covering spaces, tabs, newlines, and Unicode whitespace around basic-auth selectors accepted by the parser.
|
The failing basic auth test is unrelated. Flaky endpoint. |
|
This has been open for a while. I made a few more tweaks and switched to JSON Schema Draft 7, matching the draft used by the published SchemaStore schema. I compared both schemas against lychee's config loader. They aren't identical: the generated schema covers newer options and follows the parser more closely in several places:
The comparison also caught a bug in our handling of exclusive range endpoints, which is now fixed. Some checks still belong to the parser: for example, both schemas accept The generated file will be at @Nick2bad4u, thanks for adding the existing SchemaStore schema. Would you mind updating it to use this generated version? I'll go ahead and merge this now as the change should be rather uncontroversial. :) |
Which url do you want to use? The raw.github @ main branch since it'll pull directly from the url instead and update automatically? |
|
Maybe github has something like https://raw.githubusercontent.com/lycheeverse/lychee/tags/nightly/docs/schema.json, but for the latest full release (instead of |
master. You can rebase your branch to see the clean diff if you like. 😃