pkg/types: preserve qualified requirement text in field docs - #726
pkg/types: preserve qualified requirement text in field docs#726pujitha24 wants to merge 1 commit into
Conversation
Motivation: Upjet-generated CRD field documentation strips Terraform argument description text that clarifies when a field is actually required or optional. getDescription() in pkg/types/field.go removed any parenthesized text beginning with "(optional" or "(required" (case-insensitive), not just the plain "(Optional)"/"(Required)" markers Terraform docs use. For arguments whose requirement is conditional, e.g. AWS RDS's username: (Required unless a snapshot_identifier or replicate_source_db is provided) the entire parenthetical was discarded, leaving users with no indication of the conditional requirement until they apply the resource and it fails. Approach: Only strip a parenthetical when its trimmed, lowercased inner content is exactly "optional" or "required". Plain markers such as "(Optional)", "(required)", and "( Optional )" are still removed as before; parentheticals carrying more specific requirement text are now preserved verbatim in the generated field comment. Validation: Added a table-driven unit test, TestGetDescription, in the new pkg/types/field_test.go covering a plain "(Optional)" marker, a plain "(Required)" marker, a case-insensitive "(optional)" marker, and the reported RDS username case. Confirmed the new ComplexRequirement case fails against the pre-fix implementation (the whole parenthetical is stripped) and passes against the fix. Ran: go build ./... # succeeds go test ./pkg/types/... # all packages pass This is a pure string-processing change confined to doc-comment generation, so no e2e or dev-stack run was performed; none is required by this repo's contribution guidelines for a change of this kind. Report: crossplane#457 Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
📝 WalkthroughWalkthrough
ChangesField description cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 7✅ Passed checks (7 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/types/field_test.go (1)
38-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExpand coverage for marker normalization.
The current cases use
Optionalandoptional, but no mixed casing. No case uses spaces inside the marker, such as( Optional ). Add both cases so regressions in the case-insensitive and whitespace handling fail the test.Suggested test additions
"CaseInsensitiveOptional": { reason: "The '(optional)' marker check must be case-insensitive.", - arg: "field - (optional) Some description.", + arg: "field - (oPtIoNaL) Some description.", want: "Some description.", }, + "SpacedRequired": { + reason: "Whitespace around the marker content should be ignored.", + arg: "field - ( Required ) Some description.", + want: "Some description.", + },🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/types/field_test.go` around lines 38 - 42, Expand the test cases for marker normalization around the existing CaseInsensitiveOptional entry: add a mixed-case marker case and a marker containing internal spaces such as “( Optional )”, with expected descriptions confirming both normalize to “Some description.”
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/types/field_test.go`:
- Around line 38-42: Expand the test cases for marker normalization around the
existing CaseInsensitiveOptional entry: add a mixed-case marker case and a
marker containing internal spaces such as “( Optional )”, with expected
descriptions confirming both normalize to “Some description.”
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 7dd71f6d-fa6b-4e52-abc2-50af750a3052
📒 Files selected for processing (2)
pkg/types/field.gopkg/types/field_test.go
|
This has been rebased and green for a bit now — happy to make any changes if something would help move review along. |
Description of your changes
getDescriptioninpkg/types/field.gostrips parenthesizedspecification-requirement text from Terraform argument descriptions before
they're used as CRD field documentation. Previously it stripped any
parenthetical whose text started with "(optional" or "(required"
(case-insensitive), which discards qualifying detail beyond a plain
"(Optional)"/"(Required)" marker. For example, AWS RDS's
usernameargumentis documented as:
but the generated CRD field comment previously dropped the entire
parenthetical, leaving users with no indication that
usernamehas aconditional requirement until they apply the resource.
This change only strips a parenthetical when its trimmed, lowercased content
is exactly "optional" or "required" (so plain markers like "(Optional)",
"(required)", "( Optional )" are still removed as before), and preserves any
more specific parenthetical content instead.
Fixes #
I have:
make reviewableto ensure this PR is ready for review.backport release-x.ylabels to auto-backport this PR if necessary.How has this code been tested
Added a table-driven unit test,
TestGetDescriptioninpkg/types/field_test.go, covering a plain "(Optional)" marker, a plain"(Required)" marker, a case-insensitive "(optional)" marker, and the
reported complex-requirement case (RDS
username's"(Required unless a snapshot_identifier or replicate_source_db is
provided)"). Verified the new
ComplexRequirementtest case fails againstthe pre-fix code (it strips the whole parenthetical) and passes against the
fix.
Ran:
go build ./...— succeeds.go test ./pkg/types/...— all packages pass.This is a pure string-processing change with no behavioral impact outside of
generated doc-comment text, so no e2e/dev-stack run was needed or performed.
Fixes #457