Skip to content

Commit

Permalink
Add handling for set nested attribute/block with associated external …
Browse files Browse the repository at this point in the history
…type (#31)
  • Loading branch information
bendbennett committed Aug 10, 2023
1 parent 46c3f0e commit 5f9e61a
Show file tree
Hide file tree
Showing 13 changed files with 1,827 additions and 36 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions internal/cmd/testdata/custom_and_external/ir.json
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,52 @@
"computed_optional_required": "optional"
}
},
{
"name": "set_nested_attribute_assoc_ext_type",
"set_nested": {
"nested_object": {
"associated_external_type": {
"import": {
"path": "example.com/apisdk"
},
"type": "*apisdk.Type"
},
"attributes": [
{
"name": "bool_attribute",
"bool": {
"computed_optional_required": "computed"
}
},
{
"name": "float64_attribute",
"float64": {
"computed_optional_required": "computed_optional"
}
},
{
"name": "int64_attribute",
"int64": {
"computed_optional_required": "computed_optional"
}
},
{
"name": "number_attribute",
"number": {
"computed_optional_required": "computed_optional"
}
},
{
"name": "string_attribute",
"string": {
"computed_optional_required": "computed_optional"
}
}
]
},
"computed_optional_required": "optional"
}
},
{
"name": "single_nested_attribute_one",
"single_nested": {
Expand Down Expand Up @@ -521,6 +567,51 @@
}
}
},
{
"name": "set_nested_block_assoc_ext_type",
"set_nested": {
"nested_object": {
"associated_external_type": {
"import": {
"path": "example.com/apisdk"
},
"type": "*apisdk.Type"
},
"attributes": [
{
"name": "bool_attribute",
"bool": {
"computed_optional_required": "computed"
}
},
{
"name": "float64_attribute",
"float64": {
"computed_optional_required": "computed_optional"
}
},
{
"name": "int64_attribute",
"int64": {
"computed_optional_required": "computed_optional"
}
},
{
"name": "number_attribute",
"number": {
"computed_optional_required": "computed_optional"
}
},
{
"name": "string_attribute",
"string": {
"computed_optional_required": "computed_optional"
}
}
]
}
}
},
{
"name": "single_nested_block_one",
"single_nested": {
Expand Down
7 changes: 4 additions & 3 deletions internal/datasource_convert/set_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ func convertSetNestedAttribute(a *datasource.SetNestedAttribute) (datasource_gen

CustomType: a.CustomType,
NestedObject: datasource_generate.GeneratorNestedAttributeObject{
Attributes: attributes,
CustomType: a.NestedObject.CustomType,
Validators: a.NestedObject.Validators,
AssociatedExternalType: a.NestedObject.AssociatedExternalType,
Attributes: attributes,
CustomType: a.NestedObject.CustomType,
Validators: a.NestedObject.Validators,
},
Validators: a.Validators,
}, nil
Expand Down
9 changes: 5 additions & 4 deletions internal/datasource_convert/set_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ func convertSetNestedBlock(b *datasource.SetNestedBlock) (datasource_generate.Ge

CustomType: b.CustomType,
NestedObject: datasource_generate.GeneratorNestedBlockObject{
Attributes: attributes,
Blocks: blocks,
CustomType: b.NestedObject.CustomType,
Validators: b.NestedObject.Validators,
AssociatedExternalType: b.NestedObject.AssociatedExternalType,
Attributes: attributes,
Blocks: blocks,
CustomType: b.NestedObject.CustomType,
Validators: b.NestedObject.Validators,
},
Validators: b.Validators,
}, nil
Expand Down
7 changes: 7 additions & 0 deletions internal/datasource_generate/set_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type GeneratorSetNestedAttribute struct {
Validators []specschema.SetValidator
}

func (g GeneratorSetNestedAttribute) AssocExtType() *generatorschema.AssocExtType {
return generatorschema.NewAssocExtType(g.NestedObject.AssociatedExternalType)
}

func (g GeneratorSetNestedAttribute) AttrType() attr.Type {
return types.SetType{
//TODO: Add ElemType?
Expand Down Expand Up @@ -55,6 +59,9 @@ func (g GeneratorSetNestedAttribute) Imports() *generatorschema.Imports {
imports.Append(v.Imports())
}

// TODO: This should only be added if model object helper functions are being generated.
imports.Append(generatorschema.AttrImports())

return imports
}

Expand Down
Loading

0 comments on commit 5f9e61a

Please sign in to comment.