Skip to content

Commit

Permalink
Suffixing attribute name to prevent errors when nested attribute name…
Browse files Browse the repository at this point in the history
…s are reserved Go keywords (#76)
  • Loading branch information
bendbennett committed Oct 24, 2023
1 parent 292ce20 commit f674ce2
Show file tree
Hide file tree
Showing 12 changed files with 2,298 additions and 2,298 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions internal/schema/custom_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ return NewExampleValueUnknown(), diags
}
boolAttribute, ok := attributes["bool_attribute"]
boolAttributeAttribute, ok := attributes["bool_attribute"]
if !ok {
diags.AddError(
Expand All @@ -239,12 +239,12 @@ diags.AddError(
return NewExampleValueUnknown(), diags
}
boolAttributeVal, ok := boolAttribute.(basetypes.BoolValue)
boolAttributeVal, ok := boolAttributeAttribute.(basetypes.BoolValue)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(` + "`bool_attribute expected to be basetypes.BoolValue, was: %T`" + `, boolAttribute))
fmt.Sprintf(` + "`bool_attribute expected to be basetypes.BoolValue, was: %T`" + `, boolAttributeAttribute))
}
Expand Down Expand Up @@ -302,7 +302,7 @@ var diags diag.Diagnostics
attributes := in.Attributes()
boolAttribute, ok := attributes["bool_attribute"]
boolAttributeAttribute, ok := attributes["bool_attribute"]
if !ok {
diags.AddError(
Expand All @@ -312,12 +312,12 @@ diags.AddError(
return nil, diags
}
boolAttributeVal, ok := boolAttribute.(basetypes.BoolValue)
boolAttributeVal, ok := boolAttributeAttribute.(basetypes.BoolValue)
if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(` + "`bool_attribute expected to be basetypes.BoolValue, was: %T`" + `, boolAttribute))
fmt.Sprintf(` + "`bool_attribute expected to be basetypes.BoolValue, was: %T`" + `, boolAttributeAttribute))
}
Expand Down
6 changes: 3 additions & 3 deletions internal/schema/templates/object_type_value.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ return New{{.Name}}ValueUnknown(), diags
}

{{range $key, $value := .AttrValues }}
{{$key.ToCamelCase}}, ok := attributes["{{$key}}"]
{{$key.ToCamelCase}}Attribute, ok := attributes["{{$key}}"]

if !ok {
diags.AddError(
Expand All @@ -61,12 +61,12 @@ diags.AddError(
return New{{$.Name}}ValueUnknown(), diags
}

{{$key.ToCamelCase}}Val, ok := {{$key.ToCamelCase}}.({{$value}})
{{$key.ToCamelCase}}Val, ok := {{$key.ToCamelCase}}Attribute.({{$value}})

if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`{{$key}} expected to be {{$value}}, was: %T`, {{$key.ToCamelCase}}))
fmt.Sprintf(`{{$key}} expected to be {{$value}}, was: %T`, {{$key.ToCamelCase}}Attribute))
}
{{end}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var diags diag.Diagnostics
attributes := in.Attributes()

{{range $key, $value := .AttrValues }}
{{$key.ToCamelCase}}, ok := attributes["{{$key}}"]
{{$key.ToCamelCase}}Attribute, ok := attributes["{{$key}}"]

if !ok {
diags.AddError(
Expand All @@ -15,12 +15,12 @@ diags.AddError(
return nil, diags
}

{{$key.ToCamelCase}}Val, ok := {{$key.ToCamelCase}}.({{$value}})
{{$key.ToCamelCase}}Val, ok := {{$key.ToCamelCase}}Attribute.({{$value}})

if !ok {
diags.AddError(
"Attribute Wrong Type",
fmt.Sprintf(`{{$key}} expected to be {{$value}}, was: %T`, {{$key.ToCamelCase}}))
fmt.Sprintf(`{{$key}} expected to be {{$value}}, was: %T`, {{$key.ToCamelCase}}Attribute))
}
{{end}}

Expand Down

0 comments on commit f674ce2

Please sign in to comment.