Skip to content

Commit b8a5b77

Browse files
committed
Render blocks without specifying if they are required or optional
This avoids all blocks being rendered as optional in resources implemented with terraform-plugin-framework.
1 parent 308f0fc commit b8a5b77

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

internal/schemamd/behaviors.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,11 @@ func childBlockIsReadOnly(block *tfjson.SchemaBlockType) bool {
7777

7878
return true
7979
}
80+
81+
func childBlockIsWritable(block *tfjson.SchemaBlockType) bool {
82+
return !childBlockIsReadOnly(block)
83+
}
84+
85+
func omitChild[T *tfjson.SchemaAttribute | *tfjson.SchemaBlockType](_ T) bool {
86+
return false
87+
}

internal/schemamd/render.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ var (
5050
// * Optional
5151
// * Read-Only
5252
groupFilters = []groupFilter{
53-
{"### Required", "Required:", childAttributeIsRequired, childBlockIsRequired},
54-
{"### Optional", "Optional:", childAttributeIsOptional, childBlockIsOptional},
53+
{"### Required Attributes", "Required Attributes:", childAttributeIsRequired, omitChild[*tfjson.SchemaBlockType]},
54+
{"### Optional Attributes", "Optional Attributes:", childAttributeIsOptional, omitChild[*tfjson.SchemaBlockType]},
55+
{"### Blocks", "Blocks:", omitChild[*tfjson.SchemaAttribute], childBlockIsWritable},
5556
{"### Read-Only", "Read-Only:", childAttributeIsReadOnly, childBlockIsReadOnly},
5657
}
5758
)

0 commit comments

Comments
 (0)