-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add Automatic Validator Value Documentation #6
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
Conversation
…ttribute descriptions.
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.
Pull request overview
This PR adds automatic parsing of stringvalidator.OneOf validators to append the list of possible values to the Description and MarkdownDescription fields in generated Terraform provider code. This improves documentation visibility by showing allowed enum values directly in the schema instead of requiring external documentation.
- Implemented regex-based parsing to extract valid values from OneOf validators
- Updated resource and provider string attribute generators to call the new AppendValidators method
- Added unit tests covering basic scenarios
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| internal/convert/description_validator.go | New file implementing AppendValidators method with regex parsing to extract OneOf validator values |
| internal/convert/description_validator_test.go | New test file with basic test cases for the AppendValidators functionality |
| internal/resource/string_attribute.go | Integrates AppendValidators call for resource string attributes |
| internal/provider/string_attribute.go | Integrates AppendValidators call for provider string attributes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…neOf` arguments with commas and appends possible values to string attribute descriptions.
|
@copilot I just pushed some changes to address your comments. Review again |
|
@hanneshayashi I've opened a new pull request, #7, to work on those changes. Once the pull request is ready, I'll request review from you. |
… `go/ast` for robust argument extraction.
Summary
This PR updates the code generator to automatically parse
stringvalidator.OneOfvalidators and append the possible values to the generated Description andMarkdownDescriptionfields for string attributes.Motivation
Currently, when attributes have validators restricting their values (e.g., an enum list), these allowed values are enforced by the framework but are not visible in the attribute's description in the generated documentation or Terraform schema. This makes it difficult for users to know which values are valid without consulting external documentation or trial and error.
Changes
stringvalidator.OneOfdefinitions and extracts the list of valid strings.\nPossible values: 'value1', 'value2', ....Verification
OneOfformats (single line, multiline, etc.).terraform-provider-doitresources. Confirmed that attributes likedisplay_valuesin report_resource_gen.go now include the list of possible values in their descriptions.Example Output
Before:
Description: "See [View data as (Comparative report)](...)."After:
Description: "See [View data as (Comparative report)](...).\nPossible values: `actuals_only`, `absolute_change`, `percentage_change`, `absolute_and_percentage`"