-
Notifications
You must be signed in to change notification settings - Fork 13
feat(schema): generate config JSON Schema, folded into docgen #600
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
base: main
Are you sure you want to change the base?
Changes from all commits
12a0874
29a56d7
82f9a1e
53740c8
77f164d
331e2da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,10 @@ func (g *MarkdownGenerator) writeFieldRow(field FieldDoc, required string) { | |
| if runes := []rune(desc); len(runes) > 200 { | ||
| desc = string(runes[:197]) + "..." | ||
| } | ||
| // Append the `jsonschema` constraints after truncation, so they are never | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kudos for the ordering here. Appending constraints after truncation so a constraint can never be the part that gets cut is a small decision that keeps paying off - the 200-rune limit would otherwise silently eat exactly the most actionable half of a long description. The comment says why, and Catching the silent enum loss ( |
||
| // the part that gets cut. These are short and are the field's most | ||
| // actionable documentation. | ||
| desc = strings.TrimSpace(desc + constraintSuffix(field)) | ||
|
|
||
| yamlKey := field.YAMLKey | ||
| if yamlKey == "" { | ||
|
|
@@ -92,6 +96,28 @@ func (g *MarkdownGenerator) writeFieldRow(field FieldDoc, required string) { | |
| field.Name, yamlKey, goType, required, desc) | ||
| } | ||
|
|
||
| // constraintSuffix renders a field's `jsonschema` enum/default as a sentence | ||
| // to append to its description, so the allowed values and default a field | ||
| // declares are visible in the markdown reference and not only in schemas/. | ||
| // Returns "" when the field declares neither. | ||
| func constraintSuffix(field FieldDoc) string { | ||
| var parts []string | ||
| if len(field.Enum) > 0 { | ||
| quoted := make([]string, len(field.Enum)) | ||
| for i, v := range field.Enum { | ||
| quoted[i] = "`" + v + "`" | ||
| } | ||
| parts = append(parts, "One of: "+strings.Join(quoted, ", ")+".") | ||
| } | ||
| if field.Default != "" { | ||
| parts = append(parts, "Defaults to `"+field.Default+"`.") | ||
| } | ||
| if len(parts) == 0 { | ||
| return "" | ||
| } | ||
| return " " + strings.Join(parts, " ") | ||
| } | ||
|
|
||
| // formatType formats a Go type for markdown display. | ||
| func formatType(t string) string { | ||
| // Wrap complex types in code blocks | ||
|
|
||
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.
Question: is this govulncheck bump (v1.4.0 -> v1.6.0, plus the matching string in
scripts/govulncheck-gate.sh) meant to ride along here? It isn't in the description's Changes section, which covers the schema pipeline and the docgen fold.No objection to the bump - just that a dependency-gate change is easy to lose in a PR this size, and someone bisecting a CI failure later will want it on its own commit. Either call it out in the body or split it.