diff --git a/list_nested_type.go b/list_nested_type.go index ae13aab..cfb530b 100644 --- a/list_nested_type.go +++ b/list_nested_type.go @@ -21,7 +21,28 @@ type ListNestedType struct { } func (t ListNestedType) String() string { - return "types.ListType[" + t.ElementType().String() + "]" + return "supertypes.ListType[" + t.ElementType().String() + "]" +} + +func (t ListNestedType) Equal(o attr.Type) bool { + switch o.(type) { + case ListNestedType: + other, ok := o.(ListNestedType) + if !ok { + return false + } + + return t.ListType.Equal(other.ListType) + case basetypes.ListType: + other, ok := o.(basetypes.ListType) + if !ok { + return false + } + + return t.ListType.Equal(other) + default: + return false + } } func (t ListNestedType) ValueFromList(_ context.Context, in basetypes.ListValue) (basetypes.ListValuable, diag.Diagnostics) { diff --git a/map_nested_type.go b/map_nested_type.go index a31604f..042dbd8 100644 --- a/map_nested_type.go +++ b/map_nested_type.go @@ -21,7 +21,28 @@ type MapNestedType struct { } func (t MapNestedType) String() string { - return "types.MapType[" + t.ElementType().String() + "]" + return "supertypes.MapType[" + t.ElementType().String() + "]" +} + +func (t MapNestedType) Equal(o attr.Type) bool { + switch o.(type) { + case MapNestedType: + other, ok := o.(MapNestedType) + if !ok { + return false + } + + return t.MapType.Equal(other.MapType) + case basetypes.MapType: + other, ok := o.(basetypes.MapType) + if !ok { + return false + } + + return t.MapType.Equal(other) + default: + return false + } } func (t MapNestedType) ValueFromMap(_ context.Context, in basetypes.MapValue) (basetypes.MapValuable, diag.Diagnostics) { diff --git a/set_nested_type.go b/set_nested_type.go index 4df128c..dfaf737 100644 --- a/set_nested_type.go +++ b/set_nested_type.go @@ -21,7 +21,28 @@ type SetNestedType struct { } func (t SetNestedType) String() string { - return "types.SetType[" + t.ElementType().String() + "]" + return "supertypes.SetType[" + t.ElementType().String() + "]" +} + +func (t SetNestedType) Equal(o attr.Type) bool { + switch o.(type) { + case SetNestedType: + other, ok := o.(SetNestedType) + if !ok { + return false + } + + return t.SetType.Equal(other.SetType) + case basetypes.SetType: + other, ok := o.(basetypes.SetType) + if !ok { + return false + } + + return t.SetType.Equal(other) + default: + return false + } } func (t SetNestedType) ValueFromSet(_ context.Context, in basetypes.SetValue) (basetypes.SetValuable, diag.Diagnostics) { diff --git a/single_nested_type.go b/single_nested_type.go index 4cd76f3..02ad99f 100644 --- a/single_nested_type.go +++ b/single_nested_type.go @@ -38,6 +38,20 @@ func (t SingleNestedType) Equal(o attr.Type) bool { } return t.ObjectType.Equal(other) + case basetypes.ListType: + other, ok := o.(basetypes.ListType) + if !ok { + return false + } + + return t.ListType.Equal(other) + case basetypes.SetType: + other, ok := o.(basetypes.SetType) + if !ok { + return false + } + + return t.SetType.Equal(other) default: return false } @@ -91,8 +105,3 @@ func (t SingleNestedType) ValueFromTerraform(ctx context.Context, in tftypes.Val return value, nil } - -func (t SingleNestedType) ValueType(ctx context.Context) attr.Value { - // SingleNestedValue defined in the value type section - return SingleNestedValue{} -} \ No newline at end of file diff --git a/templates/nested_type.go.tmpl b/templates/nested_type.go.tmpl index 6c1e253..704e0ac 100644 --- a/templates/nested_type.go.tmpl +++ b/templates/nested_type.go.tmpl @@ -19,7 +19,28 @@ type {{ .TypeName }}NestedType struct { } func (t {{ .TypeName }}NestedType) String() string { - return "types.{{ .TypeName }}Type[" + t.ElementType().String() + "]" + return "supertypes.{{ .TypeName }}Type[" + t.ElementType().String() + "]" +} + +func (t {{ .TypeName }}NestedType) Equal(o attr.Type) bool { + switch o.(type) { + case {{ .TypeName }}NestedType: + other, ok := o.({{ .TypeName }}NestedType) + if !ok { + return false + } + + return t.{{ .TypeName }}Type.Equal(other.{{ .TypeName }}Type) + case basetypes.{{ .TypeName }}Type: + other, ok := o.(basetypes.{{ .TypeName }}Type) + if !ok { + return false + } + + return t.{{ .TypeName }}Type.Equal(other) + default: + return false + } } func (t {{ .TypeName }}NestedType) ValueFrom{{ .TypeName }}(_ context.Context, in basetypes.{{ .TypeName }}Value) (basetypes.{{ .TypeName }}Valuable, diag.Diagnostics) { diff --git a/templates/single_nested_type.go.tmpl b/templates/single_nested_type.go.tmpl index 0cfba14..ccd6812 100644 --- a/templates/single_nested_type.go.tmpl +++ b/templates/single_nested_type.go.tmpl @@ -21,18 +21,43 @@ type {{ .TypeName }}NestedType struct { } func (t {{ .TypeName }}NestedType) Equal(o attr.Type) bool { - other, ok := o.(basetypes.ObjectType) + switch o.(type) { + case SingleNestedType: + other, ok := o.(SingleNestedType) + if !ok { + return false + } - if !ok { + return t.ObjectType.Equal(other.ObjectType) + case basetypes.ObjectType: + other, ok := o.(basetypes.ObjectType) + if !ok { + return false + } + + return t.ObjectType.Equal(other) + case basetypes.ListType: + other, ok := o.(basetypes.ListType) + if !ok { + return false + } + + return t.ListType.Equal(other) + case basetypes.SetType: + other, ok := o.(basetypes.SetType) + if !ok { + return false + } + + return t.SetType.Equal(other) + default: return false } - - return t.ObjectType.Equal(other) } func (t {{ .TypeName }}NestedType) String() string { var res strings.Builder - res.WriteString("types.ObjectType[") + res.WriteString("supertypes.SingleNestedType[") keys := make([]string, 0, len(t.AttrTypes)) for k := range t.AttrTypes { keys = append(keys, k)