Fixes #539: Setting both "Type" and "NestedType" removes other validation error messages (#897)

Signed-off-by: Janos Bonic <86970079+janosdebugs@users.noreply.github.com>
This commit is contained in:
Janos 2023-11-21 11:57:37 +01:00 committed by GitHub
parent 70dd385136
commit 5154b14818
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -128,7 +128,7 @@ func (a *Attribute) internalValidate(name, prefix string) error {
if a.Type != cty.NilType {
if a.NestedType != nil {
err = multierror.Append(fmt.Errorf("%s: Type and NestedType cannot both be set", name))
err = multierror.Append(err, fmt.Errorf("%s: Type and NestedType cannot both be set", name))
}
}

View File

@ -134,6 +134,32 @@ func TestBlockInternalValidate(t *testing.T) {
},
[]string{"foo: either Type or NestedType must be defined"},
},
"attribute with both type and nestedtype should not suppress other validation messages": {
&Block{
Attributes: map[string]*Attribute{
"foo": {
// These properties are here to make sure other errors are also reported.
Optional: true,
Required: true,
// Here's what we actually want to validate:
Type: cty.String,
NestedType: &Object{
Nesting: NestingSingle,
Attributes: map[string]*Attribute{
"foo": {
Type: cty.String,
Required: true,
},
},
},
},
},
},
[]string{
"foo: cannot set both Optional and Required",
"foo: Type and NestedType cannot both be set",
},
},
/* FIXME: This caused errors when applied to existing providers (oci)
and cannot be enforced without coordination.