Skip to content

pkg/types: preserve qualified requirement text in field docs - #726

Open
pujitha24 wants to merge 1 commit into
crossplane:mainfrom
pujitha24:auto/issue-457
Open

pkg/types: preserve qualified requirement text in field docs#726
pujitha24 wants to merge 1 commit into
crossplane:mainfrom
pujitha24:auto/issue-457

Conversation

@pujitha24

Copy link
Copy Markdown

Description of your changes

getDescription in pkg/types/field.go strips parenthesized
specification-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 username argument
is documented as:

(Required unless a snapshot_identifier or replicate_source_db is provided)

but the generated CRD field comment previously dropped the entire
parenthetical, leaving users with no indication that username has a
conditional 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:

  • Read and followed Upjet's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Added a table-driven unit test, TestGetDescription in
pkg/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 ComplexRequirement test case fails against
the 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

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>
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

getDescription now removes only exact parenthesized optional and required markers. It preserves qualified requirement text. Table-driven tests cover the updated behavior.

Changes

Field description cleanup

Layer / File(s) Summary
Description processing and validation
pkg/types/field.go, pkg/types/field_test.go
getDescription preserves complex specification requirements while removing exact optional and required markers. Tests cover plain markers, qualified requirements, and case-insensitive optional markers.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: erhancagirici, sergenyalcin, ulucinar

🚥 Pre-merge checks | ✅ 7
✅ Passed checks (7 passed)
Check name Status Explanation
Title check ✅ Passed The title is 60 characters, clearly describes preserving qualified requirement text, and stays below the 72-character limit.
Description check ✅ Passed The description explains the documentation change, its motivation, affected behavior, tests, and validation results.
Linked Issues check ✅ Passed The implementation satisfies issue #457 by preserving complex requirement text while removing only exact optional and required markers.
Out of Scope Changes check ✅ Passed The changes are limited to the documented string-processing fix and focused unit tests for field descriptions.
Configuration Api Breaking Changes ✅ Passed The pull request changes only pkg/types/field.go and pkg/types/field_test.go; git diff shows no changes under pkg/config, so no configuration API breaking change exists.
Generated Code Manual Edits ✅ Passed The patch changes only pkg/types/field.go and pkg/types/field_test.go; no changed file matches the zz_*.go pattern.
Template Breaking Changes ✅ Passed The PR changes only pkg/types/field.go and pkg/types/field_test.go; no pkg/controller/external*.go template changes are present.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
pkg/types/field_test.go (1)

38-42: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Expand coverage for marker normalization.

The current cases use Optional and optional, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 324a879 and 6a1617c.

📒 Files selected for processing (2)
  • pkg/types/field.go
  • pkg/types/field_test.go

@pujitha24

Copy link
Copy Markdown
Author

This has been rebased and green for a bit now — happy to make any changes if something would help move review along.

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.

Field documentation should include complex specification requirements

1 participant