diff --git a/go.mod b/go.mod index 6a15633..940e628 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/google/go-cmp v0.5.9 - github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230523185217-138156557de4 + github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230621142418-132924edffa4 github.com/mattn/go-colorable v0.1.13 github.com/mitchellh/cli v1.1.5 github.com/pb33f/libopenapi v0.8.5 diff --git a/go.sum b/go.sum index 6ddf0eb..fb20965 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230523185217-138156557de4 h1:3y6OQrS16jIiiXHUiye78IwAOULEQkjGCzI5ejRdRO4= -github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230523185217-138156557de4/go.mod h1:4aZFKiOI2xiQFOpeQMMyDL8vRmKAZXHUY4kWol7Fdco= +github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230621142418-132924edffa4 h1:lIes+kZHc05eU+KTwIrdoMq5kYhjODbq1EFkU5qj5oY= +github.com/hashicorp/terraform-plugin-codegen-spec v0.0.0-20230621142418-132924edffa4/go.mod h1:4aZFKiOI2xiQFOpeQMMyDL8vRmKAZXHUY4kWol7Fdco= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= diff --git a/internal/mapper/datasource_mapper_test.go b/internal/mapper/datasource_mapper_test.go index 3cc4201..9259e09 100644 --- a/internal/mapper/datasource_mapper_test.go +++ b/internal/mapper/datasource_mapper_test.go @@ -26,7 +26,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) { testCases := map[string]struct { readResponseSchema *base.SchemaProxy readParams []*high.Parameter - want []datasource.Attribute + want datasource.Attributes }{ "merge primitives across all ops": { readParams: []*high.Parameter{ @@ -73,7 +73,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) { }), }, }), - want: []datasource.Attribute{ + want: datasource.Attributes{ { Name: "string_prop", String: &datasource.StringAttribute{ @@ -165,7 +165,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) { }), }, }), - want: []datasource.Attribute{ + want: datasource.Attributes{ { Name: "nested_object_one", SingleNested: &datasource.SingleNestedAttribute{ @@ -300,7 +300,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) { }), }, }), - want: []datasource.Attribute{ + want: datasource.Attributes{ { Name: "array_prop", ListNested: &datasource.ListNestedAttribute{ @@ -454,7 +454,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) { }), }, }), - want: []datasource.Attribute{ + want: datasource.Attributes{ { Name: "array_prop", List: &datasource.ListAttribute{ @@ -463,36 +463,42 @@ func TestDataSourceMapper_basic_merges(t *testing.T) { ElementType: schema.ElementType{ List: &schema.ListType{ ElementType: schema.ElementType{ - Object: []schema.ObjectAttributeType{ - { - Name: "deep_nested_list", - List: &schema.ListType{ - ElementType: schema.ElementType{ - Object: []schema.ObjectAttributeType{ - { - Name: "deep_deep_nested_object", - Object: []schema.ObjectAttributeType{ - { - Name: "deep_deep_nested_bool", - Bool: &schema.BoolType{}, - }, + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ + { + Name: "deep_nested_list", + List: &schema.ListType{ + ElementType: schema.ElementType{ + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ { - Name: "deep_deep_nested_string", - String: &schema.StringType{}, + Name: "deep_deep_nested_object", + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ + { + Name: "deep_deep_nested_bool", + Bool: &schema.BoolType{}, + }, + { + Name: "deep_deep_nested_string", + String: &schema.StringType{}, + }, + }, + }, }, }, }, }, }, }, - }, - { - Name: "deep_nested_bool", - Bool: &schema.BoolType{}, - }, - { - Name: "deep_nested_int64", - Int64: &schema.Int64Type{}, + { + Name: "deep_nested_bool", + Bool: &schema.BoolType{}, + }, + { + Name: "deep_nested_int64", + Int64: &schema.Int64Type{}, + }, }, }, }, diff --git a/internal/mapper/element_type_mapper.go b/internal/mapper/element_type_mapper.go index b184140..43a5e30 100644 --- a/internal/mapper/element_type_mapper.go +++ b/internal/mapper/element_type_mapper.go @@ -12,8 +12,8 @@ func mergeElementType(mainElementType schema.ElementType, secondElementType sche if mainElementType.List != nil && secondElementType.List != nil { mainElementType.List.ElementType = mergeElementType(mainElementType.List.ElementType, secondElementType.List.ElementType) } else if mainElementType.Object != nil && secondElementType.Object != nil { - objectElemTypes := mergeObjectAttributeTypes(mainElementType.Object, secondElementType.Object) - mainElementType.Object = objectElemTypes + objectElemTypes := mergeObjectAttributeTypes(mainElementType.Object.AttributeTypes, secondElementType.Object.AttributeTypes) + mainElementType.Object.AttributeTypes = objectElemTypes } return mainElementType diff --git a/internal/mapper/oas/list_test.go b/internal/mapper/oas/list_test.go index 5eb7faa..c7702a3 100644 --- a/internal/mapper/oas/list_test.go +++ b/internal/mapper/oas/list_test.go @@ -143,14 +143,16 @@ func TestBuildListResource(t *testing.T) { ElementType: schema.ElementType{ List: &schema.ListType{ ElementType: schema.ElementType{ - Object: []schema.ObjectAttributeType{ - { - Name: "float64_prop", - Float64: &schema.Float64Type{}, - }, - { - Name: "int64_prop", - Int64: &schema.Int64Type{}, + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ + { + Name: "float64_prop", + Float64: &schema.Float64Type{}, + }, + { + Name: "int64_prop", + Int64: &schema.Int64Type{}, + }, }, }, }, @@ -166,14 +168,16 @@ func TestBuildListResource(t *testing.T) { ElementType: schema.ElementType{ List: &schema.ListType{ ElementType: schema.ElementType{ - Object: []schema.ObjectAttributeType{ - { - Name: "bool_prop", - Bool: &schema.BoolType{}, - }, - { - Name: "string_prop", - String: &schema.StringType{}, + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ + { + Name: "bool_prop", + Bool: &schema.BoolType{}, + }, + { + Name: "string_prop", + String: &schema.StringType{}, + }, }, }, }, @@ -330,14 +334,16 @@ func TestBuildListDataSource(t *testing.T) { ElementType: schema.ElementType{ List: &schema.ListType{ ElementType: schema.ElementType{ - Object: []schema.ObjectAttributeType{ - { - Name: "float64_prop", - Float64: &schema.Float64Type{}, - }, - { - Name: "int64_prop", - Int64: &schema.Int64Type{}, + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ + { + Name: "float64_prop", + Float64: &schema.Float64Type{}, + }, + { + Name: "int64_prop", + Int64: &schema.Int64Type{}, + }, }, }, }, @@ -353,14 +359,16 @@ func TestBuildListDataSource(t *testing.T) { ElementType: schema.ElementType{ List: &schema.ListType{ ElementType: schema.ElementType{ - Object: []schema.ObjectAttributeType{ - { - Name: "bool_prop", - Bool: &schema.BoolType{}, - }, - { - Name: "string_prop", - String: &schema.StringType{}, + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ + { + Name: "bool_prop", + Bool: &schema.BoolType{}, + }, + { + Name: "string_prop", + String: &schema.StringType{}, + }, }, }, }, diff --git a/internal/mapper/oas/object.go b/internal/mapper/oas/object.go index b6fa468..04bdff8 100644 --- a/internal/mapper/oas/object.go +++ b/internal/mapper/oas/object.go @@ -32,6 +32,8 @@ func (s *OASSchema) BuildObjectElementType() (schema.ElementType, error) { } return schema.ElementType{ - Object: objectElemTypes, + Object: &schema.ObjectType{ + AttributeTypes: objectElemTypes, + }, }, nil } diff --git a/internal/mapper/resource_mapper_test.go b/internal/mapper/resource_mapper_test.go index 8eda0c4..01f89e8 100644 --- a/internal/mapper/resource_mapper_test.go +++ b/internal/mapper/resource_mapper_test.go @@ -28,7 +28,7 @@ func TestResourceMapper_basic_merges(t *testing.T) { createResponseSchema *base.SchemaProxy readResponseSchema *base.SchemaProxy readParams []*high.Parameter - want []resource.Attribute + want resource.Attributes }{ "merge primitives across all ops": { createRequestSchema: base.CreateSchemaProxy(&base.Schema{ @@ -75,7 +75,7 @@ func TestResourceMapper_basic_merges(t *testing.T) { }), }, }, - want: []resource.Attribute{ + want: resource.Attributes{ { Name: "bool_prop", Bool: &resource.BoolAttribute{ @@ -182,7 +182,7 @@ func TestResourceMapper_basic_merges(t *testing.T) { }), }, }, - want: []resource.Attribute{ + want: resource.Attributes{ { Name: "nested_object_one", SingleNested: &resource.SingleNestedAttribute{ @@ -324,7 +324,7 @@ func TestResourceMapper_basic_merges(t *testing.T) { }), }, }), - want: []resource.Attribute{ + want: resource.Attributes{ { Name: "array_prop", ListNested: &resource.ListNestedAttribute{ @@ -505,7 +505,7 @@ func TestResourceMapper_basic_merges(t *testing.T) { }), }, }), - want: []resource.Attribute{ + want: resource.Attributes{ { Name: "array_prop", List: &resource.ListAttribute{ @@ -514,38 +514,44 @@ func TestResourceMapper_basic_merges(t *testing.T) { ElementType: schema.ElementType{ List: &schema.ListType{ ElementType: schema.ElementType{ - Object: []schema.ObjectAttributeType{ - { - Name: "deep_nested_float64", - Float64: &schema.Float64Type{}, - }, - { - Name: "deep_nested_string", - String: &schema.StringType{}, - }, - { - Name: "deep_nested_bool", - Bool: &schema.BoolType{}, - }, - { - Name: "deep_nested_int64", - Int64: &schema.Int64Type{}, - }, - { - Name: "deep_nested_list", - List: &schema.ListType{ - ElementType: schema.ElementType{ - Object: []schema.ObjectAttributeType{ - { - Name: "deep_deep_nested_object", - Object: []schema.ObjectAttributeType{ - { - Name: "deep_deep_nested_string", - String: &schema.StringType{}, - }, + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ + { + Name: "deep_nested_float64", + Float64: &schema.Float64Type{}, + }, + { + Name: "deep_nested_string", + String: &schema.StringType{}, + }, + { + Name: "deep_nested_bool", + Bool: &schema.BoolType{}, + }, + { + Name: "deep_nested_int64", + Int64: &schema.Int64Type{}, + }, + { + Name: "deep_nested_list", + List: &schema.ListType{ + ElementType: schema.ElementType{ + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ { - Name: "deep_deep_nested_bool", - Bool: &schema.BoolType{}, + Name: "deep_deep_nested_object", + Object: &schema.ObjectType{ + AttributeTypes: []schema.ObjectAttributeType{ + { + Name: "deep_deep_nested_string", + String: &schema.StringType{}, + }, + { + Name: "deep_deep_nested_bool", + Bool: &schema.BoolType{}, + }, + }, + }, }, }, },