-
Notifications
You must be signed in to change notification settings - Fork 97
types: Add Typable and Valuable Interfaces #536
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
Conversation
… types.ListType and types.List (value), respectively (#535)
… types.MapType and types.Map (value), respectively (#535)
… types.SetType and types.Set (value), respectively (#535)
… types.ObjectType and types.Object (value), respectively (#535)
… primitive types and primitive values, respectively (#535)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks like a really good direction. We'll also want to ensure there's Go documentation for the new interfaces and methods.
types/list.go
Outdated
) | ||
|
||
type ListTyp interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To potentially make the interface naming clearer, we may want to consider using -er (🙁 ) or -able (😄 ) naming. e.g. ListTypable
and ListValuable
💰
types/list.go
Outdated
type ListTyp interface { | ||
attr.Type | ||
|
||
ValueFromFramework(context.Context, List) (attr.Value, diag.Diagnostics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing we can do since we are creating separate interfaces is name the methods to match the types now 🎉 . I'm not sure that we necessarily have a use case for it (maybe this could help if we ever wanted to implement dynamic types?), but it would then also allow custom types to support multiple type implementations.
Another thing we should likely consider here is that the returned attr.Value
can be constrained further to only matching the value interface specific to the type. e.g. in this case ListVal
/ ListValuable
ValueFromList(context.Context, List) (ListValuable, diag.Diagnostics)
types/list.go
Outdated
type ListVal interface { | ||
attr.Value | ||
|
||
ToFrameworkValue(ctx context.Context) (List, diag.Diagnostics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly with these
ToListValue(ctx context.Context) (List, diag.Diagnostics)
types/list.go
Outdated
type ListTypable interface { | ||
attr.Type | ||
|
||
ValueFromList(context.Context, List) (attr.Value, diag.Diagnostics) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing we should likely consider for these is that the returned attr.Value can be constrained further to only allowing the value interface specific to the type.
// ValueFromList should return the equivalent value from a given List.
ValueFromList(context.Context, List) (ListValuable, diag.Diagnostics)
…faces from ValueFrom<type> functions (#535)
Co-authored-by: Brian Flad <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're getting close here!
types/list.go
Outdated
// ListTypable extends attr.Type for list type types. | ||
// Implement this interface to create a custom ListType type type. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think we can just refer to the "type type" as just "type" and leave the distinction of "value type" to be separate 😎
// ListTypable extends attr.Type for list type types. | |
// Implement this interface to create a custom ListType type type. | |
// ListTypable extends attr.Type for list types. | |
// Implement this interface to create a custom ListType type. |
) | ||
|
||
// ListTypable extends attr.Type for list type types. | ||
// Implement this interface to create a custom ListType type type. | ||
type ListTypable interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add changelog entries for these? e.g.
types: Added `ListTypable` and `ListValuable` interface types, which enable embedding existing list types for custom types
Or something along those lines?
"Attribute Validation Error", | ||
"Attribute validation cannot walk schema. Report this to the provider developer:\n\n"+err.Error(), | ||
"Attribute Validation Error Invalid Value Type", | ||
"A type from which a types.List can be obtained is expected here. Report this to the provider developer:\n\n"+err.Error(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Should we give the direct hint about the types.ListValuable
interface for these?
) | ||
|
||
return | ||
} | ||
|
||
l, diags := listVal.ToListValue(ctx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're ready for unit testing these! Maybe some additional types in internal/testing/types
?
… attribute plan modification and attribute validation for custom nested attribute types (#535)
ValueFromFramework
and ToFrameworkValue
Interface Functions to attr.ValueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 🚀 Nice work.
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Closes: #535