fix: render minLength, maxLength, and pattern constraints - #364
Open
thc1006 wants to merge 1 commit into
Open
Conversation
The built-in markdown, frontmatter, and adoc templates rendered enum, format, default, minimum, maximum, and x-kubernetes-validations but omitted minLength, maxLength, and pattern, so the generated reference under-documented the API server's validation contract. Render all three across the templates. Escaping is handled per output format so a valid pattern is shown faithfully: the HTML templates (markdown, frontmatter) pass the pattern through the built-in html function, since a pattern may legally contain '<'/'>' (named capture groups) or '&'; the AsciiDoc template escapes '|' as '\|' so a regex alternation cannot start a new table cell. Add a template-output regression test (a fixture that puts each constraint on its own field, with a pattern exercising both escaping paths), wire go test ./... into the CI workflow so the test actually gates, and regenerate the example. Fixes fybrik#329 Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
thc1006
force-pushed
the
render-string-constraints
branch
from
July 11, 2026 05:24
77aae22 to
f036f75
Compare
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.
Summary
The built-in
markdown.tmpl,frontmatter.tmpl, andadoc.tmpltemplates render several OpenAPI schema constraints, including
enum,format,default,minimum,maximum, andx-kubernetes-validations.However, they omit
minLength,maxLength, andpatternfrom thegenerated documentation, even though these values are already available
in each field's
apiextensions.JSONSchemaProps.As a result, the generated reference does not fully describe the API
server's validation contract.
This PR renders all three string constraints in every built-in output
template.
Changes
Update
markdown.tmplandfrontmatter.tmplto renderMin Length,Max Length, andPattern, and include these fields in the spacer guard.Update
adoc.tmplto render the same constraints.Escape the pattern per output format so a valid pattern is shown faithfully:
markdown.tmpl,frontmatter.tmpl) pass the patternthrough the built-in
htmlfunction. A pattern may legally contain<and>(Go named capture groups(?P<name>...)/(?<name>...)) or&, whichan HTML renderer would otherwise misinterpret.
|as\|(via Sprig'sreplace), since|is the default AsciiDoc table-cell separator and is also common in regex
alternation.
Wire
go test ./...into thetestCI workflow so the new regression testactually gates (the workflow previously only regenerated the example).
Update the example CRD and regenerate
example/output.md.No parser or model changes are required because the field model already
retains
MinLength,MaxLength, andPattern.Testing
Added
pkg/builder/templates_test.goandpkg/builder/testdata/constraints.yaml.The fixture puts each constraint on its own field so a guard branch cannot be
covered by an unrelated sibling, and its pattern carries a named capture group
(
<,>), an entity-like sequence (&), and an alternation (|). The testsverify, for each built-in template, that:
Min Length,Max Length, andPatternall render;<,>, and&(a negative assertion ensuresthe raw named-capture group does not leak into the HTML);
|as\|(a negative assertion ensures nounescaped separator is emitted).
Verified with:
go test ./...The three templates were also rendered through crdoc to confirm the
generated Markdown, front-matter Markdown, and AsciiDoc output.
Fixes #329