diff --git a/cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_all_framework_types.txtar b/cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_all_framework_types.txtar index b58019ee..e98192bb 100644 --- a/cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_all_framework_types.txtar +++ b/cmd/tfplugindocs/testdata/scripts/schema-json/generate/framework_provider_success_all_framework_types.txtar @@ -93,6 +93,7 @@ example resource - `single_nested_block` (Block, Optional) example single nested block (see [below for nested schema](#nestedblock--single_nested_block)) - `single_nested_block_sensitive_nested_attribute` (Block, Optional) example sensitive single nested block (see [below for nested schema](#nestedblock--single_nested_block_sensitive_nested_attribute)) - `string_attribute` (String) example string attribute +- `write_only_string_attribute` (String, Write-only) example write-only string attribute ### Read-Only @@ -418,6 +419,13 @@ scaffolding(stringInput string, boolInput bool, float64Input number, int64Input "description": "example string attribute", "description_kind": "markdown", "optional": true + }, + "write_only_string_attribute": { + "type": "string", + "description": "example write-only string attribute", + "description_kind": "markdown", + "optional": true, + "write_only": true } }, "block_types": { diff --git a/internal/schemamd/behaviors.go b/internal/schemamd/behaviors.go index f0006ef2..561f34c1 100644 --- a/internal/schemamd/behaviors.go +++ b/internal/schemamd/behaviors.go @@ -19,7 +19,7 @@ func childAttributeIsOptional(att *tfjson.SchemaAttribute) bool { return att.Optional } -// childBlockIsOptional returns true for blocks with with min items 0 +// childBlockIsOptional returns true for blocks with min items 0 // which are either empty or have any required or optional children. func childBlockIsOptional(block *tfjson.SchemaBlockType) bool { if block.MinItems > 0 { diff --git a/internal/schemamd/render_test.go b/internal/schemamd/render_test.go index 1770be42..75314dd5 100644 --- a/internal/schemamd/render_test.go +++ b/internal/schemamd/render_test.go @@ -54,6 +54,11 @@ func TestRender(t *testing.T) { "testdata/deep_nested_attributes.schema.json", "testdata/deep_nested_attributes.md", }, + { + "deep_nested_write_only_attributes", + "testdata/deep_nested_write_only_attributes.schema.json", + "testdata/deep_nested_write_only_attributes.md", + }, } { c := c t.Run(c.name, func(t *testing.T) { diff --git a/internal/schemamd/testdata/deep_nested_write_only_attributes.md b/internal/schemamd/testdata/deep_nested_write_only_attributes.md new file mode 100644 index 00000000..b421fad2 --- /dev/null +++ b/internal/schemamd/testdata/deep_nested_write_only_attributes.md @@ -0,0 +1,46 @@ +## Schema + +### Required + +- `level_one` (Attributes) (see [below for nested schema](#nestedatt--level_one)) + +### Read-Only + +- `id` (String) Example identifier + + +### Nested Schema for `level_one` + +Optional: + +- `level_two` (Attributes, Write-only) (see [below for nested schema](#nestedatt--level_one--level_two)) + + +### Nested Schema for `level_one.level_two` + +Optional: + +- `level_three` (Attributes, Write-only) (see [below for nested schema](#nestedatt--level_one--level_two--level_three)) + + +### Nested Schema for `level_one.level_two.level_three` + +Optional: + +- `level_four_primary` (Attributes, Write-only) (see [below for nested schema](#nestedatt--level_one--level_two--level_three--level_four_primary)) +- `level_four_secondary` (String, Write-only) + + +### Nested Schema for `level_one.level_two.level_three.level_four_primary` + +Optional: + +- `level_five` (Attributes, Write-only) Parent should be level_one.level_two.level_three.level_four_primary. (see [below for nested schema](#nestedatt--level_one--level_two--level_three--level_four_primary--level_five)) +- `level_four_primary_string` (String, Write-only) Parent should be level_one.level_two.level_three.level_four_primary. + + +### Nested Schema for `level_one.level_two.level_three.level_four_primary.level_five` + +Optional: + +- `level_five_string` (String, Write-only) Parent should be level_one.level_two.level_three.level_four_primary.level_five. diff --git a/internal/schemamd/testdata/deep_nested_write_only_attributes.schema.json b/internal/schemamd/testdata/deep_nested_write_only_attributes.schema.json new file mode 100644 index 00000000..5ba4fe27 --- /dev/null +++ b/internal/schemamd/testdata/deep_nested_write_only_attributes.schema.json @@ -0,0 +1,85 @@ +{ + "version": 0, + "block": { + "attributes": { + "id": { + "type": "string", + "description": "Example identifier", + "description_kind": "markdown", + "computed": true + }, + "level_one": { + "nested_type": { + "attributes": { + "level_two": { + "nested_type": { + "attributes": { + "level_three": { + "nested_type": { + "attributes": { + "level_four_primary": { + "nested_type": { + "attributes": { + "level_five": { + "nested_type": { + "attributes": { + "level_five_string": { + "type": "string", + "description": "Parent should be level_one.level_two.level_three.level_four_primary.level_five.", + "description_kind": "plain", + "optional": true, + "write_only": true + } + }, + "nesting_mode": "single" + }, + "description": "Parent should be level_one.level_two.level_three.level_four_primary.", + "description_kind": "plain", + "optional": true, + "write_only": true + }, + "level_four_primary_string": { + "type": "string", + "description": "Parent should be level_one.level_two.level_three.level_four_primary.", + "description_kind": "plain", + "optional": true, + "write_only": true + } + }, + "nesting_mode": "single" + }, + "description_kind": "plain", + "optional": true, + "write_only": true + }, + "level_four_secondary": { + "type": "string", + "description_kind": "plain", + "optional": true, + "write_only": true + } + }, + "nesting_mode": "single" + }, + "description_kind": "plain", + "optional": true, + "write_only": true + } + }, + "nesting_mode": "single" + }, + "description_kind": "plain", + "optional": true, + "write_only": true + } + }, + "nesting_mode": "single" + }, + "description_kind": "plain", + "required": true + } + }, + "description": "Example resource", + "description_kind": "markdown" + } +} \ No newline at end of file diff --git a/internal/schemamd/testdata/framework_types.md b/internal/schemamd/testdata/framework_types.md index 06c04261..781b5bd2 100644 --- a/internal/schemamd/testdata/framework_types.md +++ b/internal/schemamd/testdata/framework_types.md @@ -26,6 +26,7 @@ - `single_nested_block` (Block, Optional) example single nested block (see [below for nested schema](#nestedblock--single_nested_block)) - `single_nested_block_sensitive_nested_attribute` (Block, Optional) example sensitive single nested block (see [below for nested schema](#nestedblock--single_nested_block_sensitive_nested_attribute)) - `string_attribute` (String) example string attribute +- `write_only_string_attribute` (String, Write-only) example write only string attribute ### Read-Only @@ -39,6 +40,7 @@ Optional: - `list_nested_block_attribute` (String) example list nested block attribute - `list_nested_block_attribute_with_default` (String) example list nested block attribute with default +- `list_nested_block_write_only_attribute` (String, Write-only) example list nested block write-only attribute - `nested_list_block` (Block List) (see [below for nested schema](#nestedblock--list_nested_block--nested_list_block)) @@ -98,6 +100,7 @@ Optional: Optional: - `set_nested_block_attribute` (String) example set nested block attribute +- `set_nested_block_write_only_attribute` (String, Write-only) example set nested block write-only attribute @@ -123,4 +126,4 @@ Optional: Read-Only: - `set_nested_block_attribute` (String) example set nested block attribute -- `set_nested_block_sensitive_attribute` (String, Sensitive) example sensitive set nested block attribute +- `set_nested_block_sensitive_attribute` (String, Sensitive) example sensitive set nested block attribute \ No newline at end of file diff --git a/internal/schemamd/testdata/framework_types.schema.json b/internal/schemamd/testdata/framework_types.schema.json index 9aac7817..eb7d810a 100644 --- a/internal/schemamd/testdata/framework_types.schema.json +++ b/internal/schemamd/testdata/framework_types.schema.json @@ -168,6 +168,13 @@ "description": "example string attribute", "description_kind": "markdown", "optional": true + }, + "write_only_string_attribute": { + "type": "string", + "description": "example write only string attribute", + "description_kind": "markdown", + "optional": true, + "write_only": true } }, "block_types": { @@ -181,6 +188,13 @@ "description_kind": "markdown", "optional": true }, + "list_nested_block_write_only_attribute": { + "type": "string", + "description": "example list nested block write-only attribute", + "description_kind": "markdown", + "optional": true, + "write_only": true + }, "list_nested_block_attribute_with_default": { "type": "string", "description": "example list nested block attribute with default", @@ -239,6 +253,13 @@ "description": "example set nested block attribute", "description_kind": "markdown", "optional": true + }, + "set_nested_block_write_only_attribute": { + "type": "string", + "description": "example set nested block write-only attribute", + "description_kind": "markdown", + "optional": true, + "write_only": true } }, "description": "example set nested block", diff --git a/internal/schemamd/write_attribute_description.go b/internal/schemamd/write_attribute_description.go index a8aa45b9..f31cccfe 100644 --- a/internal/schemamd/write_attribute_description.go +++ b/internal/schemamd/write_attribute_description.go @@ -58,6 +58,13 @@ func WriteAttributeDescription(w io.Writer, att *tfjson.SchemaAttribute, include } } + if att.WriteOnly { + _, err := io.WriteString(w, ", Write-only") + if err != nil { + return err + } + } + _, err = io.WriteString(w, ")") if err != nil { return err diff --git a/internal/schemamd/write_attribute_description_test.go b/internal/schemamd/write_attribute_description_test.go index c1318425..3df5c6dd 100644 --- a/internal/schemamd/write_attribute_description_test.go +++ b/internal/schemamd/write_attribute_description_test.go @@ -30,6 +30,15 @@ func TestWriteAttributeDescription(t *testing.T) { Description: "This is an attribute.", }, }, + { + "(String, Required, Write-only) This is an attribute.", + &tfjson.SchemaAttribute{ + AttributeType: cty.String, + Required: true, + Description: "This is an attribute.", + WriteOnly: true, + }, + }, { "(String, Required, Deprecated) This is an attribute.", &tfjson.SchemaAttribute{ diff --git a/internal/schemamd/write_nested_attribute_type_description.go b/internal/schemamd/write_nested_attribute_type_description.go index c51be83c..c2f0c117 100644 --- a/internal/schemamd/write_nested_attribute_type_description.go +++ b/internal/schemamd/write_nested_attribute_type_description.go @@ -97,6 +97,13 @@ func WriteNestedAttributeTypeDescription(w io.Writer, att *tfjson.SchemaAttribut } } + if att.WriteOnly { + _, err := io.WriteString(w, ", Write-only") + if err != nil { + return err + } + } + _, err = io.WriteString(w, ")") if err != nil { return err diff --git a/internal/schemamd/write_nested_attribute_type_description_test.go b/internal/schemamd/write_nested_attribute_type_description_test.go index 170284c1..698b27cb 100644 --- a/internal/schemamd/write_nested_attribute_type_description_test.go +++ b/internal/schemamd/write_nested_attribute_type_description_test.go @@ -38,6 +38,24 @@ func TestWriteNestedAttributeTypeDescription(t *testing.T) { Optional: true, }, }, + { + "(Attributes, Optional, Write-only) This is an attribute.", + &tfjson.SchemaAttribute{ + Description: "This is an attribute.", + AttributeNestedType: &tfjson.SchemaNestedAttributeType{ + NestingMode: tfjson.SchemaNestingModeSingle, + Attributes: map[string]*tfjson.SchemaAttribute{ + "foo": { + AttributeType: cty.String, + Required: true, + Description: "This is a nested attribute.", + }, + }, + }, + Optional: true, + WriteOnly: true, + }, + }, { "(Attributes List, Min: 2, Max: 3) This is an attribute.", &tfjson.SchemaAttribute{