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

Added write-only support to generate #434

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added write-only as a descriptor, handled similarly to "sensitive"
  • Loading branch information
rainkwan committed Jan 16, 2025
commit 6611fc10c16a9b8c2f65ea8c91f43b0a7a08aabf
6 changes: 5 additions & 1 deletion internal/schemamd/behaviors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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 {
Expand Down Expand Up @@ -77,3 +77,7 @@

return true
}

func childAttributeIsWriteOnly(att *tfjson.SchemaAttribute) bool {

Check failure on line 81 in internal/schemamd/behaviors.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

func `childAttributeIsWriteOnly` is unused (unused)
return att.WriteOnly
}
2 changes: 1 addition & 1 deletion internal/schemamd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type groupFilter struct {
}

var (
// Attributes and Blocks are in one of 3 characteristic groups:
// Attributes and Blocks are in one of 4 characteristic groups:
rainkwan marked this conversation as resolved.
Show resolved Hide resolved
// * Required
// * Optional
// * Read-Only
Expand Down
3 changes: 2 additions & 1 deletion internal/schemamd/testdata/framework_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -123,4 +124,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
7 changes: 7 additions & 0 deletions internal/schemamd/testdata/framework_types.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 7 additions & 0 deletions internal/schemamd/write_attribute_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading