Skip to content

Commit

Permalink
Add handling for list, map, set, single nested attributes and blocks …
Browse files Browse the repository at this point in the history
…for provider and resource (#31)
  • Loading branch information
bendbennett committed Aug 10, 2023
1 parent 5f9e61a commit 6aa6290
Show file tree
Hide file tree
Showing 45 changed files with 4,166 additions and 761 deletions.
3 changes: 1 addition & 2 deletions internal/datasource_convert/single_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ func convertSingleNestedAttribute(a *datasource.SingleNestedAttribute) (datasour
DeprecationMessage: deprecationMessage(a.DeprecationMessage),
},

Attributes: attributes,

AssociatedExternalType: a.AssociatedExternalType,
Attributes: attributes,
CustomType: a.CustomType,
Validators: a.Validators,
}, nil
Expand Down
5 changes: 2 additions & 3 deletions internal/datasource_convert/single_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ func convertSingleNestedBlock(b *datasource.SingleNestedBlock) (datasource_gener
DeprecationMessage: deprecationMessage(b.DeprecationMessage),
},

Attributes: attributes,
Blocks: blocks,

AssociatedExternalType: b.AssociatedExternalType,
Attributes: attributes,
Blocks: blocks,
CustomType: b.CustomType,
Validators: b.Validators,
}, nil
Expand Down
7 changes: 4 additions & 3 deletions internal/provider_convert/list_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ func convertListNestedAttribute(a *provider.ListNestedAttribute) (provider_gener

CustomType: a.CustomType,
NestedObject: provider_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/provider_convert/list_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ func convertListNestedBlock(b *provider.ListNestedBlock) (provider_generate.Gene

CustomType: b.CustomType,
NestedObject: provider_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: 4 additions & 3 deletions internal/provider_convert/map_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ func convertMapNestedAttribute(a *provider.MapNestedAttribute) (provider_generat

CustomType: a.CustomType,
NestedObject: provider_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
7 changes: 4 additions & 3 deletions internal/provider_convert/set_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ func convertSetNestedAttribute(a *provider.SetNestedAttribute) (provider_generat

CustomType: a.CustomType,
NestedObject: provider_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/provider_convert/set_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ func convertSetNestedBlock(b *provider.SetNestedBlock) (provider_generate.Genera

CustomType: b.CustomType,
NestedObject: provider_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: 4 additions & 3 deletions internal/provider_convert/single_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ func convertSingleNestedAttribute(a *provider.SingleNestedAttribute) (provider_g
MarkdownDescription: description(a.Description),
DeprecationMessage: deprecationMessage(a.DeprecationMessage),
},
Attributes: attributes,
CustomType: a.CustomType,
Validators: a.Validators,
AssociatedExternalType: a.AssociatedExternalType,
Attributes: attributes,
CustomType: a.CustomType,
Validators: a.Validators,
}, nil
}
7 changes: 7 additions & 0 deletions internal/provider_generate/list_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type GeneratorListNestedAttribute struct {
Validators []specschema.ListValidator
}

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

func (g GeneratorListNestedAttribute) AttrType() attr.Type {
return types.ListType{
//TODO: Add ElemType?
Expand Down Expand Up @@ -55,6 +59,9 @@ func (g GeneratorListNestedAttribute) 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
70 changes: 68 additions & 2 deletions internal/provider_generate/list_nested_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: generatorschema.TypesImport,
},
{
Path: generatorschema.AttrImport,
},
},
},
"custom-type-without-import": {
Expand All @@ -36,6 +39,8 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
expected: []code.Import{
{
Path: generatorschema.TypesImport,
}, {
Path: generatorschema.AttrImport,
},
},
},
Expand All @@ -49,6 +54,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: generatorschema.TypesImport,
},
{
Path: generatorschema.AttrImport,
},
},
},
"custom-type-and-nested-object-custom-type-without-import": {
Expand All @@ -58,7 +66,11 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
CustomType: &specschema.CustomType{},
},
},
expected: []code.Import{},
expected: []code.Import{
{
Path: generatorschema.AttrImport,
},
},
},
"custom-type-with-import-empty-string": {
input: GeneratorListNestedAttribute{
Expand All @@ -71,6 +83,8 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
expected: []code.Import{
{
Path: generatorschema.TypesImport,
}, {
Path: generatorschema.AttrImport,
},
},
},
Expand All @@ -87,6 +101,8 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
expected: []code.Import{
{
Path: generatorschema.TypesImport,
}, {
Path: generatorschema.AttrImport,
},
},
},
Expand All @@ -105,7 +121,11 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
},
},
},
expected: []code.Import{},
expected: []code.Import{
{
Path: generatorschema.AttrImport,
},
},
},
"custom-type-with-import": {
input: GeneratorListNestedAttribute{
Expand All @@ -122,6 +142,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: generatorschema.TypesImport,
},
{
Path: generatorschema.AttrImport,
},
},
},
"nested-object-custom-type-with-import": {
Expand All @@ -141,6 +164,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: "github.com/my_account/my_project/attribute",
},
{
Path: generatorschema.AttrImport,
},
},
},
"custom-type-with-import-with-nested-object-custom-type-with-import": {
Expand All @@ -164,6 +190,8 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
},
{
Path: "github.com/my_account/my_project/nested_object",
}, {
Path: generatorschema.AttrImport,
},
},
},
Expand All @@ -182,6 +210,8 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
expected: []code.Import{
{
Path: generatorschema.TypesImport,
}, {
Path: generatorschema.AttrImport,
},
},
},
Expand All @@ -206,6 +236,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: "github.com/my_account/my_project/nested_list",
},
{
Path: generatorschema.AttrImport,
},
},
},
"nested-list-with-custom-type-with-element-with-custom-type": {
Expand Down Expand Up @@ -241,6 +274,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: "github.com/my_account/my_project/bool",
},
{
Path: generatorschema.AttrImport,
},
},
},
"nested-object": {
Expand Down Expand Up @@ -288,6 +324,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: "github.com/my_account/my_project/nested_object",
},
{
Path: generatorschema.AttrImport,
},
},
},
"nested-object-with-custom-type-with-attribute-with-custom-type": {
Expand Down Expand Up @@ -326,6 +365,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: "github.com/my_account/my_project/bool",
},
{
Path: generatorschema.AttrImport,
},
},
},
"validator-custom-nil": {
Expand All @@ -339,6 +381,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: generatorschema.TypesImport,
},
{
Path: generatorschema.AttrImport,
},
},
},
"validator-custom-import-nil": {
Expand All @@ -352,6 +397,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: generatorschema.TypesImport,
},
{
Path: generatorschema.AttrImport,
},
},
},
"validator-custom-import-empty-string": {
Expand All @@ -371,6 +419,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: generatorschema.TypesImport,
},
{
Path: generatorschema.AttrImport,
},
},
},
"validator-custom-import": {
Expand Down Expand Up @@ -408,6 +459,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: "github.com/myproject/myvalidators/validator",
},
{
Path: generatorschema.AttrImport,
},
},
},
"nested-object-validator-custom-nil": {
Expand All @@ -424,6 +478,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: generatorschema.TypesImport,
},
{
Path: generatorschema.AttrImport,
},
},
},
"nested-object-validator-custom-import-nil": {
Expand All @@ -440,6 +497,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: generatorschema.TypesImport,
},
{
Path: generatorschema.AttrImport,
},
},
},
"nested-object-validator-custom-import-empty-string": {
Expand All @@ -462,6 +522,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: generatorschema.TypesImport,
},
{
Path: generatorschema.AttrImport,
},
},
},
"nested-object-validator-custom-import": {
Expand Down Expand Up @@ -502,6 +565,9 @@ func TestGeneratorListNestedAttribute_Imports(t *testing.T) {
{
Path: "github.com/myproject/myvalidators/validator",
},
{
Path: generatorschema.AttrImport,
},
},
},
}
Expand Down
7 changes: 7 additions & 0 deletions internal/provider_generate/list_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type GeneratorListNestedBlock struct {
Validators []specschema.ListValidator
}

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

func (g GeneratorListNestedBlock) AttrType() attr.Type {
return types.ListType{
//TODO: Add ElemType?
Expand Down Expand Up @@ -59,6 +63,9 @@ func (g GeneratorListNestedBlock) 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 6aa6290

Please sign in to comment.