-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
d6c8b06
commit 4d10c17
Showing
7 changed files
with
1,282 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: ENHANCEMENTS | ||
body: 'all: Added embedded struct support for object to struct conversions with `tfsdk` | ||
tags' | ||
time: 2024-07-22T17:51:16.833264-04:00 | ||
custom: | ||
Issue: "1021" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
kind: NOTES | ||
body: | | ||
Framework reflection logic (`Config.Get`, `Plan.Get`, etc.) for structs with | ||
`tfsdk` field tags has been updated to support embedded structs that promote exported | ||
fields. For existing structs that embed unexported structs with exported fields, a tfsdk | ||
ignore tag (``tfsdk:"-"``) can be added to ignore all promoted fields. | ||
For example, the following struct will now return an error diagnostic: | ||
```go | ||
type thingResourceModel struct { | ||
Attr1 types.String `tfsdk:"attr_1"` | ||
Attr2 types.Bool `tfsdk:"attr_2"` | ||
// Previously, this embedded struct was ignored, will now promote underlying fields | ||
embeddedModel | ||
} | ||
type embeddedModel struct { | ||
// No `tfsdk` tag | ||
ExportedField string | ||
} | ||
``` | ||
To preserve the original behavior, a tfsdk ignore tag can be added to ignore the entire embedded struct: | ||
```go | ||
type thingResourceModel struct { | ||
Attr1 types.String `tfsdk:"attr_1"` | ||
Attr2 types.Bool `tfsdk:"attr_2"` | ||
// This embedded struct will now be ignored | ||
embeddedModel `tfsdk:"-"` | ||
} | ||
type embeddedModel struct { | ||
ExportedField string | ||
} | ||
``` | ||
time: 2024-08-01T17:16:54.043432-04:00 | ||
custom: | ||
Issue: "1021" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.