Skip to content
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

Place default ID attribute in Read Only group #46

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Expand Up @@ -3,7 +3,11 @@
ENHANCEMENTS:

* template functions: Added `split` to help separating a string into substrings ([#70](https://github.com/hashicorp/terraform-plugin-docs/pull/70)).


BUG FIXES:

* schemamd: By default `ID` attribute should be "Read Only", unless there's a description defined, in which case it's handled like any other attribute in the schema ([#46](https://github.com/hashicorp/terraform-plugin-docs/pull/46)).

# 0.7.0 (March 15, 2022)

ENHANCEMENTS:
Expand Down
12 changes: 7 additions & 5 deletions schemamd/render.go
Expand Up @@ -70,10 +70,6 @@ func writeAttribute(w io.Writer, path []string, att *tfjson.SchemaAttribute, gro
return nil, err
}

if name == "id" && att.Description == "" {
att.Description = "The ID of this resource."
}

if att.AttributeNestedType == nil {
err = WriteAttributeDescription(w, att, false)
} else {
Expand Down Expand Up @@ -225,7 +221,13 @@ nameLoop:
}
} else if childAtt, ok := block.Attributes[n]; ok {
for i, gf := range groupFilters {
if gf.filterAttribute(childAtt) {
if strings.ToLower(n) == "id" && childAtt.Description == "" {
if gf.topLevelTitle == "Read-Only" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you verify this? Because I think this won't match anything: I believe the string is ### Read-Only.

It would be even better if the elements of groupFilters above existed as variables themselves, and so you could directly match that and avoid bugs out of string mismatches (now and in the future).

Copy link
Contributor

Choose a reason for hiding this comment

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

That's correct, I have it working with that change (see below).

childAtt.Description = "The ID of this resource."
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed you are not removing anymore the if here that sets the description for id. What changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it's also necessary to remove that, and I'm not sure it's worth checking for empty description here anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we don't do that, all descriptions currently set on IDs will be overridden by this change, making it impossible for users to tailor-make the description they want.

Copy link
Contributor

Choose a reason for hiding this comment

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

But then only the description setting should be inside this condition, not the appending to Read-Only group too?

groups[i] = append(groups[i], n)
continue nameLoop
}
} else if gf.filterAttribute(childAtt) {
groups[i] = append(groups[i], n)
continue nameLoop
}
Expand Down