Skip to content

Conversation

@hanneshayashi
Copy link
Collaborator

Summary

This PR updates the code generator to automatically parse stringvalidator.OneOf validators and append the possible values to the generated Description and MarkdownDescription fields 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

  • New Logic (internal/convert/description_validator.go): Implemented AppendValidators method on the Description struct. This method uses regex to find stringvalidator.OneOf definitions and extracts the list of valid strings.
  • Generator Update (internal/provider/string_attribute.go, internal/resource/string_attribute.go): Updated the string attribute generators to call AppendValidators when constructing the attribute description.
  • Output: The description is appended with \nPossible values: 'value1', 'value2', ....

Verification

  • Added unit tests in internal/convert/description_validator_test.go to verify value extraction from various OneOf formats (single line, multiline, etc.).
  • Verified locally by regenerating the terraform-provider-doit resources. Confirmed that attributes like display_values in 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`"

Copy link

Copilot AI left a 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.
@hanneshayashi
Copy link
Collaborator Author

@copilot I just pushed some changes to address your comments. Review again

Copy link

Copilot AI commented Jan 7, 2026

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

@hanneshayashi hanneshayashi merged commit b39e80a into main Jan 7, 2026
2 checks passed
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.

2 participants