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

Merged
merged 13 commits into from
Feb 13, 2025
Merged
5 changes: 5 additions & 0 deletions .changes/unreleased/FEATURES-20250212-165819.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: FEATURES
body: 'generate: Add support for write-only arguments'
time: 2025-02-12T16:58:19.098098-05:00
custom:
Issue: "434"
6 changes: 3 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
issues:
max-per-linter: 0
max-issues-per-linter: 0
max-same-issues: 0

linters:
disable-all: true
enable:
- copyloopvar
- durationcheck
- errcheck
- exportloopref
- forcetypeassert
- gofmt
- gosimple
Expand All @@ -19,10 +19,10 @@ linters:
- paralleltest
- predeclared
- staticcheck
- tenv
- unconvert
- unparam
- unused
- usetesting

run:
# Prevent false positive timeouts in CI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 0 additions & 2 deletions internal/check/directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ func TestMixedDirectoriesCheck(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions internal/check/file_extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ func TestTrimFileExtension(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
got := TrimFileExtension(testCase.Path)
Expand Down
12 changes: 0 additions & 12 deletions internal/check/file_mismatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func TestFileHasResource(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -78,8 +76,6 @@ func TestFileResourceName(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
got := fileResourceNameWithProvider("test", testCase.File)
Expand Down Expand Up @@ -333,8 +329,6 @@ func TestFileMismatchCheck(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -381,8 +375,6 @@ func TestResourceHasFile(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -424,8 +416,6 @@ func TestFunctionHasFile(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -464,8 +454,6 @@ func TestResourceNames(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 0 additions & 4 deletions internal/check/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func TestFileSizeCheck(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -83,8 +81,6 @@ func TestFullPath(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions internal/check/frontmatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ subcategory: Example Subcategory
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions internal/provider/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ func Test_resourceSchema(t *testing.T) {
}

for name, c := range cases {
name := name
c := c
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
14 changes: 0 additions & 14 deletions internal/provider/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ func TestValidateStaticDocs_DirectoryChecks(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -409,8 +407,6 @@ func TestValidateStaticDocs_FileChecks(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -557,8 +553,6 @@ func TestValidateStaticDocs_FileMismatchCheck(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -671,8 +665,6 @@ func TestValidateLegacyWebsite_DirectoryChecks(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -905,8 +897,6 @@ func TestValidateLegacyWebsite_FileChecks(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1053,8 +1043,6 @@ func TestValidateLegacyWebsite_FileMismatchCheck(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1116,8 +1104,6 @@ func TestDocumentationDirGlobPattern(t *testing.T) {
}

for name, testCase := range testCases {
name := name
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion internal/schemamd/behaviors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions internal/schemamd/behaviors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestChildAttributeIsRequired(t *testing.T) {
false,
},
} {
c := c

t.Run(c.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -76,7 +76,7 @@ func TestChildAttributeIsOptional(t *testing.T) {
true,
},
} {
c := c

t.Run(c.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -133,7 +133,7 @@ func TestChildAttributeIsReadOnly(t *testing.T) {
true,
},
} {
c := c

t.Run(c.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -189,7 +189,7 @@ func TestChildBlockIsRequired(t *testing.T) {
false,
},
} {
c := c

t.Run(c.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -359,7 +359,7 @@ func TestChildBlockIsOptional(t *testing.T) {
true,
},
} {
c := c

t.Run(c.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -519,7 +519,7 @@ func TestChildBlockIsReadOnly(t *testing.T) {
true,
},
} {
c := c

t.Run(c.name, func(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 5 additions & 1 deletion internal/schemamd/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ 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) {
t.Parallel()

Expand Down
46 changes: 46 additions & 0 deletions internal/schemamd/testdata/deep_nested_write_only_attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Schema

### Required

- `level_one` (Attributes) (see [below for nested schema](#nestedatt--level_one))

### Read-Only

- `id` (String) Example identifier

<a id="nestedatt--level_one"></a>
### Nested Schema for `level_one`

Optional:

- `level_two` (Attributes, Write-only) (see [below for nested schema](#nestedatt--level_one--level_two))

<a id="nestedatt--level_one--level_two"></a>
### 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))

<a id="nestedatt--level_one--level_two--level_three"></a>
### 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)

<a id="nestedatt--level_one--level_two--level_three--level_four_primary"></a>
### 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.

<a id="nestedatt--level_one--level_two--level_three--level_four_primary--level_five"></a>
### 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.
Loading
Loading