Skip to content

fix: render minLength, maxLength, and pattern constraints - #364

Open
thc1006 wants to merge 1 commit into
fybrik:mainfrom
thc1006:render-string-constraints
Open

fix: render minLength, maxLength, and pattern constraints#364
thc1006 wants to merge 1 commit into
fybrik:mainfrom
thc1006:render-string-constraints

Conversation

@thc1006

@thc1006 thc1006 commented Jul 11, 2026

Copy link
Copy Markdown

Summary

The built-in markdown.tmpl, frontmatter.tmpl, and adoc.tmpl
templates render several OpenAPI schema constraints, including enum,
format, default, minimum, maximum, and
x-kubernetes-validations.

However, they omit minLength, maxLength, and pattern from the
generated 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.tmpl and frontmatter.tmpl to render Min Length,
    Max Length, and Pattern, and include these fields in the spacer guard.

  • Update adoc.tmpl to render the same constraints.

  • Escape the pattern per output format so a valid pattern is shown faithfully:

    • The HTML templates (markdown.tmpl, frontmatter.tmpl) pass the pattern
      through the built-in html function. A pattern may legally contain < and
      > (Go named capture groups (?P<name>...) / (?<name>...)) or &, which
      an HTML renderer would otherwise misinterpret.
    • The AsciiDoc template escapes | as \| (via Sprig's replace), since |
      is the default AsciiDoc table-cell separator and is also common in regex
      alternation.
  • Wire go test ./... into the test CI workflow so the new regression test
    actually 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, and Pattern.

Testing

Added pkg/builder/templates_test.go and
pkg/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 tests
verify, for each built-in template, that:

  • Min Length, Max Length, and Pattern all render;
  • the HTML templates HTML-escape <, >, and & (a negative assertion ensures
    the raw named-capture group does not leak into the HTML);
  • the AsciiDoc template escapes | as \| (a negative assertion ensures no
    unescaped 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

Copilot AI review requested due to automatic review settings July 11, 2026 04:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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
thc1006 force-pushed the render-string-constraints branch from 77aae22 to f036f75 Compare July 11, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for regexp "pattern"

2 participants