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
I want to make a list that validates its contents, such as a list of IP addresses
Attempted Solutions
I created an entirely separate type called ValidatedList. This does work, but it prevents anything that is used to dealing with types.List (such as pre-made validators) from interacting with those lists.
Another solution would be to use listvalidator.ValuesAre, but if the value creator (in the case of IPs for example) fails by creating a nil value (such as un-parseable IP), then this cannot work.
Proposal
Implement xattr.TypeWithValidate's Validate function in lists (and possibly other collections)
Add type coercion to collection types and if their element type is a xattr.TypeWithValidate, run its Validate function and actr accordingly.
References
I could not find any prior issue referring to xattr.TypeWithValidate in collections.
The text was updated successfully, but these errors were encountered:
Doridian
changed the title
xattr.TypeWithValidate support for list elements (and contents of other collections)
xattr.TypeWithValidate support for list elements (and possibly contents of other collections)
Sep 4, 2022
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Module version
Use-cases
I want to make a list that validates its contents, such as a list of IP addresses
Attempted Solutions
I created an entirely separate type called
ValidatedList
. This does work, but it prevents anything that is used to dealing withtypes.List
(such as pre-made validators) from interacting with those lists.See my currently working solutin (albeit without the build-in validators I'd love to be able to use): https://github.com/Doridian/terraform-provider-hexonet/blob/main/hexonet/utils/validated_list.go
Another solution would be to use
listvalidator.ValuesAre
, but if the value creator (in the case of IPs for example) fails by creating anil
value (such as un-parseable IP), then this cannot work.Proposal
Implement
xattr.TypeWithValidate
'sValidate
function in lists (and possibly other collections)Add type coercion to collection types and if their element type is a
xattr.TypeWithValidate
, run itsValidate
function and actr accordingly.References
I could not find any prior issue referring to
xattr.TypeWithValidate
in collections.The text was updated successfully, but these errors were encountered: