Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
62 changes: 34 additions & 28 deletions internal/mapper/datasource_mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) {
}),
},
}),
want: []datasource.Attribute{
want: datasource.Attributes{
{
Name: "string_prop",
String: &datasource.StringAttribute{
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) {
}),
},
}),
want: []datasource.Attribute{
want: datasource.Attributes{
{
Name: "nested_object_one",
SingleNested: &datasource.SingleNestedAttribute{
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) {
}),
},
}),
want: []datasource.Attribute{
want: datasource.Attributes{
{
Name: "array_prop",
ListNested: &datasource.ListNestedAttribute{
Expand Down Expand Up @@ -454,7 +454,7 @@ func TestDataSourceMapper_basic_merges(t *testing.T) {
}),
},
}),
want: []datasource.Attribute{
want: datasource.Attributes{
{
Name: "array_prop",
List: &datasource.ListAttribute{
Expand All @@ -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{},
},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/mapper/element_type_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 40 additions & 32 deletions internal/mapper/oas/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
},
},
},
},
Expand All @@ -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{},
},
},
},
},
Expand Down Expand Up @@ -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{},
},
},
},
},
Expand All @@ -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{},
},
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion internal/mapper/oas/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func (s *OASSchema) BuildObjectElementType() (schema.ElementType, error) {
}

return schema.ElementType{
Object: objectElemTypes,
Object: &schema.ObjectType{
AttributeTypes: objectElemTypes,
},
}, nil
}
78 changes: 42 additions & 36 deletions internal/mapper/resource_mapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestResourceMapper_basic_merges(t *testing.T) {
}),
},
},
want: []resource.Attribute{
want: resource.Attributes{
{
Name: "bool_prop",
Bool: &resource.BoolAttribute{
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestResourceMapper_basic_merges(t *testing.T) {
}),
},
},
want: []resource.Attribute{
want: resource.Attributes{
{
Name: "nested_object_one",
SingleNested: &resource.SingleNestedAttribute{
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestResourceMapper_basic_merges(t *testing.T) {
}),
},
}),
want: []resource.Attribute{
want: resource.Attributes{
{
Name: "array_prop",
ListNested: &resource.ListNestedAttribute{
Expand Down Expand Up @@ -505,7 +505,7 @@ func TestResourceMapper_basic_merges(t *testing.T) {
}),
},
}),
want: []resource.Attribute{
want: resource.Attributes{
{
Name: "array_prop",
List: &resource.ListAttribute{
Expand All @@ -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{},
},
},
},
},
},
},
Expand Down