-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Machine-readable config description #17892
base: develop
Are you sure you want to change the base?
Conversation
|
||
def main() -> None: | ||
try: | ||
script_name = "???.py" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
script_name = "???.py" |
@@ -0,0 +1 @@ | |||
Generate config documentation from JSON Schema file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed this PR in a weekly meeting to make sure that this is something we want to do. People are onboard with the benefits 👍
We just have to make sure this implementation is something we want to use and we won't be kicking ourselves months down the line that it's difficult to express constraints, validation, or formatting.
I reviewed the diff of the config documentation and fixed up some accidental differences that I saw, as well as some other minor improvements (IMO). Due to time constraints I have yet to deal with these issues:
Due to a problem with my diff viewer and long lines (???), some descriptions were cut off whilst I was reading them and I have not yet re-reviewed those fragments:
I thought the section on 'resources' in the listeners section looked suspicious but did not thoroughly re-review yet. Questions (aimed at the team):
Thoughts:
Things missing from this PR that I think are needed:
Things missing from this PR that can probably wait:
Risks:
If we accepted this PR now but for some reason didn't like it later:
|
(without yet looking too deeply into the implementation) those benefits definitely sound worth it, if it's not painful to do. |
Nice to see you involved, I’m really glad you’re going with this MR! :)
One important lesson I learned since starting with schemas is: behavior should be the same whether an option is unset or null. This is especially true if JSON documents are combined into a single document with one or more of those slightly weird and slightly different merge algorithms (looking at you, Helm).
Right, I think
Oups, I got confused with float inf values. "infinity" would be semantically fitting here, though.
Change it like this? {
"type": ["array", "string"],
"oneOf": [
{
"type": ["array"]
},
{
"type": ["string"],
"const": "*"
}
],
"default": "*"
}
I don’t see a strong reason against that. Depending on the tool, one might have to convert it back to JSON first.
The null type might be special-cased as an adjective like optional (“optional string”) to be closer to natural language, if that is what you want. I think a good word would apply to an unset as well as a null property.
“Defaults to an empty map” might be something you are more comfortable with.
The conversion is pretty easy to do. Regarding the |
I’m not too experienced with GitHub CI, but those two snippets should do the job. # Assert schema is valid
boon schemas/synapse-config.schema.json Running in a clean git workspace: # Regenerate config
scripts-dev/gen_config_documentation.py schemas/synapse-config.schema.json > docs/usage/configuration/config_documentation.md
# Print all modifications
git diff
# Check if any files were modified.
! git status --porcelain=1 | grep "^ M" |
Admittedly I didn't look! It's what we're used to in Matrix's JSON I guess (and reverse domain name is probably a Java influence). If the JSONSchema spec says anything about this, let's follow that, otherwise I think this convention is probably most familiar to people working on Synapse and makes it easy to distinguish from some standardised field. |
Adds a JSON Schema description of the Synapse configuration to the repo, together with a script generating docs/usage/config_documentation.md from it.
This has many advantages, one can:
I was surprised how aligned the expressiveness of the schema file is with the current infos from the Synapse documentation. Besides added types and defaults, some whitespace differences, and minor changes to wording and ordering, the config documentation remains mostly unchanged. But still, it is no perfect match, with the most important restrictions being:
I expect there will be some feedback to work into this MR before it can get merged. I’m especially thinking about CI integration, JSON Schema IDs, types and defaults, and discussions about workflow – as well as a good amount of fixes due to the size of the change. Looking forward to your comments :)
Example
Running the script
scripts-dev/gen_config_documentation.py schemas/synapse-config.schema.json > docs/usage/configuration/config_documentation.md
on a schema containing the following fragment
yields the corresponding Synapse documentation as Markdown:
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.(run the linters)