You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
all: Add support for embedded struct types in object conversions (#1021)
* add embedded struct support via field indices
* add support for unexported embedded structs and better panic protection
* adjusting error messaging and adding tests
* add test for duplicates inside of embedded struct
* add exported struct to tests
* add ignore tests for entire embedded struct
* add a test for multiple levels of embedding
* comment
* comment
* move comment
* add documentation for embedded structs
* added changelog
* add tests for tfsdk tags on embedded structs
* refactor to use Tag.Lookup and add tests for empty tags
* added note changelog for existing structs
returnnil, fmt.Errorf("embedded struct %q promotes a field with a duplicate tfsdk tag %q, conflicts with %q tfsdk tag", field.Name, k, otherField.Name)
103
+
}
104
+
105
+
tags[k] =append(fieldIndexSequence, v...)
106
+
}
107
+
continue
108
+
}
109
+
110
+
// All non-embedded fields must have a tfsdk tag
111
+
if!tagExists {
68
112
returnnil, fmt.Errorf(`%s: need a struct tag for "tfsdk" on %s`, path, field.Name)
69
113
}
114
+
115
+
// Ensure the tfsdk tag has a valid name
70
116
path:=path.AtName(tag)
71
117
if!isValidFieldName(tag) {
72
-
returnnil, fmt.Errorf("%s: invalid field name, must only use lowercase letters, underscores, and numbers, and must start with a letter", path)
118
+
returnnil, fmt.Errorf("%s: invalid tfsdk tag, must only use lowercase letters, underscores, and numbers, and must start with a letter", path)
73
119
}
120
+
121
+
// Ensure there are no duplicate tfsdk tags
74
122
ifother, ok:=tags[tag]; ok {
75
-
returnnil, fmt.Errorf("%s: can't use field name for both %s and %s", path, typ.Field(other).Name, field.Name)
123
+
otherField:=typ.FieldByIndex(other)
124
+
returnnil, fmt.Errorf("%s: can't use tfsdk tag %q for both %s and %s fields", path, tag, otherField.Name, field.Name)
0 commit comments