From e6cc7a3d5daeeacd34ed6599ea2bf69206310d47 Mon Sep 17 00:00:00 2001 From: Nicholas Muesch Date: Thu, 4 Mar 2021 15:04:24 -0500 Subject: [PATCH 1/6] Place default ID attribute in Read Only group --- schemamd/render.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/schemamd/render.go b/schemamd/render.go index 0bd0dc91..1bd7e804 100644 --- a/schemamd/render.go +++ b/schemamd/render.go @@ -25,6 +25,7 @@ func Render(schema *tfjson.Schema, w io.Writer) error { } type groupFilter struct { + name string topLevelTitle string nestedTitle string @@ -34,9 +35,9 @@ type groupFilter struct { var ( groupFilters = []groupFilter{ - {"### Required", "Required:", childIsRequired}, - {"### Optional", "Optional:", childIsOptional}, - {"### Read-Only", "Read-Only:", childIsReadOnly}, + {"Required", "### Required", "Required:", childIsRequired}, + {"Optional", "### Optional", "Optional:", childIsOptional}, + {"Read Only", "### Read-Only", "Read-Only:", childIsReadOnly}, } ) @@ -161,7 +162,12 @@ func writeBlockChildren(w io.Writer, parents []string, block *tfjson.SchemaBlock childBlock := block.NestedBlocks[n] childAtt := block.Attributes[n] for i, gf := range groupFilters { - if gf.filter(childBlock, childAtt) { + if n == "id" && childAtt.Description == "" { + if gf.name == "Read Only" { + groups[i] = append(groups[i], n) + goto NextName + } + } else if gf.filter(childBlock, childAtt) { groups[i] = append(groups[i], n) goto NextName } From 40b0963b9557cc071b34cff62c5a0884a15be8a1 Mon Sep 17 00:00:00 2001 From: Nicholas Muesch Date: Thu, 4 Mar 2021 15:27:17 -0500 Subject: [PATCH 2/6] Remove extra check of empty ID description --- schemamd/render.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/schemamd/render.go b/schemamd/render.go index 1bd7e804..17f7e602 100644 --- a/schemamd/render.go +++ b/schemamd/render.go @@ -58,10 +58,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." - } - err = WriteAttributeDescription(w, att, false) if err != nil { return nil, err @@ -164,6 +160,7 @@ func writeBlockChildren(w io.Writer, parents []string, block *tfjson.SchemaBlock for i, gf := range groupFilters { if n == "id" && childAtt.Description == "" { if gf.name == "Read Only" { + childAtt.Description = "The ID of this resource." groups[i] = append(groups[i], n) goto NextName } From 5e66e5372065e1becd017753aeab28771121cccb Mon Sep 17 00:00:00 2001 From: Nicholas Muesch Date: Tue, 26 Apr 2022 12:50:55 -0400 Subject: [PATCH 3/6] Address feedback --- CHANGELOG.md | 6 +++++- schemamd/render.go | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69cbeb08..a89ef6e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: Place the default "ID" attribute as a "Read Only" attribute, unless there's a defined description ([#46](https://github.com/hashicorp/terraform-plugin-docs/pull/46)). + # 0.7.0 (March 15, 2022) ENHANCEMENTS: diff --git a/schemamd/render.go b/schemamd/render.go index 68568c6d..c5e7db8e 100644 --- a/schemamd/render.go +++ b/schemamd/render.go @@ -225,6 +225,13 @@ nameLoop: } } else if childAtt, ok := block.Attributes[n]; ok { for i, gf := range groupFilters { + if strings.ToLower(n) == "id" && childAtt.Description == "" { + if gf.topLevelTitle == "Read-Only" { + childAtt.Description = "The ID of this resource." + groups[i] = append(groups[i], n) + continue nameLoop + } + } if gf.filterAttribute(childAtt) { groups[i] = append(groups[i], n) continue nameLoop From af5eaa6fd27f2df1fd515aeb575496624a55df5b Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Tue, 3 May 2022 10:16:49 +0100 Subject: [PATCH 4/6] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a89ef6e0..457dc2bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ENHANCEMENTS: BUG FIXES: -* schemamd: Place the default "ID" attribute as a "Read Only" attribute, unless there's a defined description ([#46](https://github.com/hashicorp/terraform-plugin-docs/pull/46)). +* 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) From 3ad1834d6c32c82ca234bdb254289f67c9b06559 Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Tue, 3 May 2022 10:17:36 +0100 Subject: [PATCH 5/6] Update schemamd/render.go Co-authored-by: Oliver Ford --- schemamd/render.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/schemamd/render.go b/schemamd/render.go index c5e7db8e..fd05ffd8 100644 --- a/schemamd/render.go +++ b/schemamd/render.go @@ -231,8 +231,7 @@ nameLoop: groups[i] = append(groups[i], n) continue nameLoop } - } - if gf.filterAttribute(childAtt) { + } else if gf.filterAttribute(childAtt) { groups[i] = append(groups[i], n) continue nameLoop } From 9ee2af142a5098150a2d64a72cb69c74540e5951 Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Tue, 3 May 2022 10:24:55 +0100 Subject: [PATCH 6/6] Update render.go --- schemamd/render.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/schemamd/render.go b/schemamd/render.go index fd05ffd8..dbf86087 100644 --- a/schemamd/render.go +++ b/schemamd/render.go @@ -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 {