Skip to content

docs: add auto-generated config TOML reference - #621

Open
m4tx wants to merge 2 commits into
masterfrom
toml-reference
Open

m4tx wants to merge 2 commits into
masterfrom
toml-reference

Conversation

@m4tx

@m4tx m4tx commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

This adds an automated script that generates a Guide page about the
configuration by using JsonSchema of the config structures in config.rs.
In addition to that, there's a new test added to cot-test
that checks whether the markdown file in the repository is up to date.

This has two huge advantages:

  1. There is a full specification of the config file now, making it much
    easier to find out what the correct values are.
  2. The specification never gets out of date, because the CI pipeline
    forces the guide page to be updated.

The reason we store the markdown file in the repository instead of
generating it on the fly is mainly so that any changes to the
documentation can be easily reviewed.

The workflow is therefore as following:

  1. A change is made to the config structures in config.rs.
  2. The change author regenerates the guide with just generate-config-docs.
  3. The changes are reviewed when a PR is made.
  4. Whenever the generated result is not up to our standards, either the
    docs or the generation script is modified.

There are some limitations of the page generation script, such as:

  • The script only takes the first paragraph of the rustdoc, so the links
    need to be inlined - referencing links defined later in the doc will
    not work.
  • Some types are not supported - e.g. [cache.timeout] displays the
    type of the value is just string, even though it needs to be
    a specific string that represents a time duration.

The config page "cheats" a little bit to be more readable, e.g.
it reduces the padding of the content. See cot-rs/cot-site#111
for the details.

Fixes #479

Copilot AI review requested due to automatic review settings July 23, 2026 20:16
@m4tx m4tx changed the title feat: add auto-generated config TOML reference docs: add auto-generated config TOML reference Jul 23, 2026
@github-actions github-actions Bot added A-docs Area: Documentation A-deps Area: Dependencies C-lib Crate: cot (main library crate) labels Jul 23, 2026
@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

🐰 Bencher Report

Projectcot
Branchtoml-reference
Testbedgithub-ubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
empty_router/empty_router📈 view plot
🚷 view threshold
10,194.00 µs
(-1.84%)Baseline: 10,385.29 µs
18,868.39 µs
(54.03%)
json_api/json_api📈 view plot
🚷 view threshold
772.08 µs
(-24.45%)Baseline: 1,021.93 µs
1,353.98 µs
(57.02%)
nested_routers/nested_routers📈 view plot
🚷 view threshold
751.85 µs
(-21.68%)Baseline: 960.02 µs
1,253.62 µs
(59.97%)
single_root_route/single_root_route📈 view plot
🚷 view threshold
738.01 µs
(-20.08%)Baseline: 923.41 µs
1,214.61 µs
(60.76%)
single_root_route_burst/single_root_route_burst📈 view plot
🚷 view threshold
14,846.00 µs
(-11.72%)Baseline: 16,817.31 µs
21,960.95 µs
(67.60%)
🐰 View full continuous benchmarking report in Bencher

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an auto-generated TOML configuration reference to the documentation, sourced from cot::config::ProjectConfig via JSON Schema so the docs stay in sync with the actual config surface.

Changes:

  • Introduces a schemars-based generator plus a cot-test test to enforce docs/configuration.md freshness.
  • Adds a config-docs internal feature to enable JSON Schema derivation for config types.
  • Wires the new configuration page into the docs site navigation and adds a just task to regenerate the docs.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
justfile Adds a just generate-config-docs helper to regenerate the config reference.
docs/site/src/main.rs Adds the new “Configuration” page to the docs site nav.
docs/configuration.md New generated configuration reference page.
cot/src/email/transport/smtp.rs Enables JSON Schema derivation for SMTP auth mechanism enum (for docs generation).
cot/src/config.rs Adds JsonSchema derives / schema overrides to config types to support docs generation.
cot/Cargo.toml Adds internal config-docs feature to drive schema generation.
cot-test/tests/config_reference.rs Adds a test that fails if docs/configuration.md is out of date.
cot-test/src/lib.rs Exposes the config reference generator behind config-docs.
cot-test/src/config_reference.rs Implements the Markdown generator from the ProjectConfig schema.
cot-test/src/bin/generate_config_docs.rs Adds a binary to write the generated docs file.
cot-test/Cargo.toml Adds deps and feature wiring for the docs generator/test/bin.
Cargo.lock Records new dependency additions for schema generation.
Comments suppressed due to low confidence (1)

cot/src/config.rs:1799

  • Using schemars(with = "Option<String>") for expiry: Expiry implies the config schema accepts null, even though the TOML representation is a string and the field is defaulted (optional-by-omission, not nullable). Prefer schemars(with = "String") here to keep the schema accurate.
    #[cfg_attr(feature = "config-docs", schemars(with = "Option<String>"))]

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cot-test/Cargo.toml Outdated
Comment thread cot/src/config.rs Outdated
Comment thread cot-test/src/config_reference.rs
@m4tx
m4tx force-pushed the toml-reference branch 3 times, most recently from 4809c4c to 51db33f Compare August 29, 2026 20:53
@github-actions github-actions Bot added C-cli Crate: cot-cli (issues and Pull Requests related to Cot CLI) C-macros Crate: cot-macros C-core labels Sep 14, 2026
@m4tx
m4tx force-pushed the toml-reference branch 4 times, most recently from e0fb363 to 704e28e Compare September 19, 2026 13:39
This adds an automated script that generates a Guide page about the
configuration by using JsonSchema of the config structures in config.rs.
In addition to that, there's a new test added to cot-test
that checks whether the markdown file in the repository is up to date.

This has two huge advantages:
1. There is a full specification of the config file now, making it much
   easier to find out what the correct values are.
2. The specification never gets out of date, because the CI pipeline
   forces the guide page to be updated.

The reason we store the markdown file in the repository instead of
generating it on the fly is mainly so that any changes to the
documentation can be easily reviewed.

The workflow is therefore as following:
1. A change is made to the config structures in config.rs.
2. The change author regenerates the guide with `just
   generate-config-docs`.
3. The changes are reviewed when a PR is made.
4. Whenever the generated result is not up to our standards, either the
   docs or the generation script is modified.

There are some limitations of the page generation script, such as:
* The script only takes the first paragraph of the rustdoc, so the links
  need to be inlined - referencing links defined later in the doc will
  not work.
* Some types are not supported - e.g. `[cache.timeout]` displays the
  type of the value is just `string`, even though it needs to be
  a specific string that represents a time duration.

The config page "cheats" a little bit to be more readable, e.g.
it reduces the padding of the content. See cot-rs/cot-site#111
for the details.

Fixes #479
@m4tx

m4tx commented Sep 19, 2026

Copy link
Copy Markdown
Member Author

The current screenshot:

Screenshot 2026-09-19 at 15-43-30 Configuration Guide Cot

@m4tx
m4tx marked this pull request as ready for review September 19, 2026 13:45
@m4tx
m4tx requested a review from a team September 19, 2026 13:45
@codecov

codecov Bot commented Sep 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.28065% with 32 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cot-test/src/config_reference.rs 94.10% 16 Missing and 5 partials ⚠️
cot-test/src/bin/generate_config_docs.rs 0.00% 11 Missing ⚠️
Flag Coverage Δ
rust 90.06% <91.28%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cot-test/src/lib.rs 76.76% <ø> (ø)
cot/src/config.rs 94.58% <ø> (ø)
cot/src/email/transport/smtp.rs 89.56% <ø> (ø)
cot-test/src/bin/generate_config_docs.rs 0.00% <0.00%> (ø)
cot-test/src/config_reference.rs 94.10% <94.10%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread docs/configuration.md
| `max_retries` | integer | `3` | Maximum number of retries for cache operations. |
| `timeout` | string | `"5m"` | Timeout for cache operations. |
| `prefix` | string | — | Prefix for cache keys. |
| `store` | table | [`type = "memory"`](#cachestore) | The cache store configuration. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I get the idea behind showing that default here, but I don't like how it looks like, especially with the 3-column layout for the page the table is really narrow. I think I'd just link to section below where the default is visible

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In my opinion, I think the current table is fine, considering that most default values are not long strings. Keeping the default value inline reduces the cognitive load of having to move between sections to find it.

That also draws my attention to cases like:

### [cache]
| `store` | `table` | `"type" = "memory"` |

### [`middlewares.session`]
| `store` | `table` | `"type" = "memory"` |

### [`email`]
| `transport` | `table` | `"type" = "console"` |

Shouldn't the default values for these say “see below,” just like sections likemiddlewares.live_load?

Comment thread docs/configuration.md
| `register_panic_hook` | boolean | `true` | Whether to register a panic hook. |
| `secret_key` | string | — | The secret key used for signing cookies and other sensitive data. This is a cryptographic key, should be kept secret, and should be set to a random and unique value for each project. |
| `fallback_secret_keys` | array of strings | `[]` | Fallback secret keys that can be used to verify old sessions. |
| `auth_backend` | table | [`type = "none"`](#auth_backend) | The authentication backend to use. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: I wonder whether using table as the type fits here. It reads like the actual type used in code rather than a docs-specific label, which could be confusing given that we use types like String elsewhere.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-deps Area: Dependencies A-docs Area: Documentation C-cli Crate: cot-cli (issues and Pull Requests related to Cot CLI) C-core C-lib Crate: cot (main library crate) C-macros Crate: cot-macros

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a full reference for config.toml files

4 participants