Skip to content

Commit

Permalink
Refactored adding Imports() method to AssocExtType and switching attr…
Browse files Browse the repository at this point in the history
…ibutes to implementing AssocExtType (#31)
  • Loading branch information
bendbennett committed Aug 14, 2023
1 parent 63e9d9a commit 05abb31
Show file tree
Hide file tree
Showing 51 changed files with 246 additions and 161 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions internal/datasource_convert/bool_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func convertBoolAttribute(a *datasource.BoolAttribute) (datasource_generate.Gene
DeprecationMessage: deprecationMessage(a.DeprecationMessage),
},

AssociatedExternalType: a.AssociatedExternalType,
CustomType: a.CustomType,
Validators: a.Validators,
CustomType: a.CustomType,
Validators: a.Validators,
}, nil
}
2 changes: 1 addition & 1 deletion internal/datasource_convert/list_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func convertListNestedAttribute(a *datasource.ListNestedAttribute) (datasource_g

CustomType: a.CustomType,
NestedObject: datasource_generate.GeneratorNestedAttributeObject{
AssociatedExternalType: a.NestedObject.AssociatedExternalType,
AssociatedExternalType: generatorschema.NewAssocExtType(a.NestedObject.AssociatedExternalType),
Attributes: attributes,
CustomType: a.NestedObject.CustomType,
Validators: a.NestedObject.Validators,
Expand Down
7 changes: 3 additions & 4 deletions internal/datasource_convert/list_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ func convertListNestedBlock(b *datasource.ListNestedBlock) (datasource_generate.

CustomType: b.CustomType,
NestedObject: datasource_generate.GeneratorNestedBlockObject{
Attributes: attributes,
Blocks: blocks,

AssociatedExternalType: b.NestedObject.AssociatedExternalType,
AssociatedExternalType: generatorschema.NewAssocExtType(b.NestedObject.AssociatedExternalType),
Attributes: attributes,
Blocks: blocks,
CustomType: b.NestedObject.CustomType,
Validators: b.NestedObject.Validators,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/datasource_convert/map_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func convertMapNestedAttribute(a *datasource.MapNestedAttribute) (datasource_gen

CustomType: a.CustomType,
NestedObject: datasource_generate.GeneratorNestedAttributeObject{
AssociatedExternalType: a.NestedObject.AssociatedExternalType,
AssociatedExternalType: generatorschema.NewAssocExtType(a.NestedObject.AssociatedExternalType),
Attributes: attributes,
CustomType: a.NestedObject.CustomType,
Validators: a.NestedObject.Validators,
Expand Down
2 changes: 1 addition & 1 deletion internal/datasource_convert/set_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func convertSetNestedAttribute(a *datasource.SetNestedAttribute) (datasource_gen

CustomType: a.CustomType,
NestedObject: datasource_generate.GeneratorNestedAttributeObject{
AssociatedExternalType: a.NestedObject.AssociatedExternalType,
AssociatedExternalType: generatorschema.NewAssocExtType(a.NestedObject.AssociatedExternalType),
Attributes: attributes,
CustomType: a.NestedObject.CustomType,
Validators: a.NestedObject.Validators,
Expand Down
2 changes: 1 addition & 1 deletion internal/datasource_convert/set_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func convertSetNestedBlock(b *datasource.SetNestedBlock) (datasource_generate.Ge

CustomType: b.CustomType,
NestedObject: datasource_generate.GeneratorNestedBlockObject{
AssociatedExternalType: b.NestedObject.AssociatedExternalType,
AssociatedExternalType: generatorschema.NewAssocExtType(b.NestedObject.AssociatedExternalType),
Attributes: attributes,
Blocks: blocks,
CustomType: b.NestedObject.CustomType,
Expand Down
2 changes: 1 addition & 1 deletion internal/datasource_convert/single_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func convertSingleNestedAttribute(a *datasource.SingleNestedAttribute) (datasour
DeprecationMessage: deprecationMessage(a.DeprecationMessage),
},

AssociatedExternalType: a.AssociatedExternalType,
AssociatedExternalType: generatorschema.NewAssocExtType(a.AssociatedExternalType),
Attributes: attributes,
CustomType: a.CustomType,
Validators: a.Validators,
Expand Down
2 changes: 1 addition & 1 deletion internal/datasource_convert/single_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func convertSingleNestedBlock(b *datasource.SingleNestedBlock) (datasource_gener
DeprecationMessage: deprecationMessage(b.DeprecationMessage),
},

AssociatedExternalType: b.AssociatedExternalType,
AssociatedExternalType: generatorschema.NewAssocExtType(b.AssociatedExternalType),
Attributes: attributes,
Blocks: blocks,
CustomType: b.CustomType,
Expand Down
12 changes: 2 additions & 10 deletions internal/datasource_generate/bool_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ type GeneratorBoolAttribute struct {

// The "specschema" types are used instead of the types within the attribute
// because support for extracting custom import information is required.
AssociatedExternalType *specschema.AssociatedExternalType
CustomType *specschema.CustomType
Validators []specschema.BoolValidator
}

func (g GeneratorBoolAttribute) AssocExtType() *generatorschema.AssocExtType {
return generatorschema.NewAssocExtType(g.AssociatedExternalType)
CustomType *specschema.CustomType
Validators []specschema.BoolValidator
}

func (g GeneratorBoolAttribute) AttrType() attr.Type {
Expand All @@ -45,9 +40,6 @@ func (g GeneratorBoolAttribute) Imports() *generatorschema.Imports {
imports.Append(customValidatorImports)
}

assocExtTypeImports := generatorschema.AssociatedExternalTypeImports(g.AssociatedExternalType)
imports.Append(assocExtTypeImports)

return imports
}

Expand Down
5 changes: 2 additions & 3 deletions internal/datasource_generate/list_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type GeneratorListNestedAttribute struct {
}

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

func (g GeneratorListNestedAttribute) AttrType() attr.Type {
Expand Down Expand Up @@ -62,8 +62,7 @@ func (g GeneratorListNestedAttribute) Imports() *generatorschema.Imports {
// TODO: This should only be added if model object helper functions are being generated.
imports.Append(generatorschema.AttrImports())

assocExtTypeImports := generatorschema.AssociatedExternalTypeImports(g.NestedObject.AssociatedExternalType)
imports.Append(assocExtTypeImports)
imports.Append(g.NestedObject.AssociatedExternalType.Imports())

return imports
}
Expand Down
5 changes: 2 additions & 3 deletions internal/datasource_generate/list_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type GeneratorListNestedBlock struct {
}

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

func (g GeneratorListNestedBlock) AttrType() attr.Type {
Expand Down Expand Up @@ -66,8 +66,7 @@ func (g GeneratorListNestedBlock) Imports() *generatorschema.Imports {
// TODO: This should only be added if model object helper functions are being generated.
imports.Append(generatorschema.AttrImports())

assocExtTypeImports := generatorschema.AssociatedExternalTypeImports(g.NestedObject.AssociatedExternalType)
imports.Append(assocExtTypeImports)
imports.Append(g.NestedObject.AssociatedExternalType.Imports())

return imports
}
Expand Down
5 changes: 2 additions & 3 deletions internal/datasource_generate/map_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type GeneratorMapNestedAttribute struct {
}

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

func (g GeneratorMapNestedAttribute) AttrType() attr.Type {
Expand Down Expand Up @@ -62,8 +62,7 @@ func (g GeneratorMapNestedAttribute) Imports() *generatorschema.Imports {
// TODO: This should only be added if model object helper functions are being generated.
imports.Append(generatorschema.AttrImports())

assocExtTypeImports := generatorschema.AssociatedExternalTypeImports(g.NestedObject.AssociatedExternalType)
imports.Append(assocExtTypeImports)
imports.Append(g.NestedObject.AssociatedExternalType.Imports())

return imports
}
Expand Down
5 changes: 2 additions & 3 deletions internal/datasource_generate/set_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type GeneratorSetNestedAttribute struct {
}

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

func (g GeneratorSetNestedAttribute) AttrType() attr.Type {
Expand Down Expand Up @@ -62,8 +62,7 @@ func (g GeneratorSetNestedAttribute) Imports() *generatorschema.Imports {
// TODO: This should only be added if model object helper functions are being generated.
imports.Append(generatorschema.AttrImports())

assocExtTypeImports := generatorschema.AssociatedExternalTypeImports(g.NestedObject.AssociatedExternalType)
imports.Append(assocExtTypeImports)
imports.Append(g.NestedObject.AssociatedExternalType.Imports())

return imports
}
Expand Down
5 changes: 2 additions & 3 deletions internal/datasource_generate/set_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type GeneratorSetNestedBlock struct {
}

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

func (g GeneratorSetNestedBlock) AttrType() attr.Type {
Expand Down Expand Up @@ -66,8 +66,7 @@ func (g GeneratorSetNestedBlock) Imports() *generatorschema.Imports {
// TODO: This should only be added if model object helper functions are being generated.
imports.Append(generatorschema.AttrImports())

assocExtTypeImports := generatorschema.AssociatedExternalTypeImports(g.NestedObject.AssociatedExternalType)
imports.Append(assocExtTypeImports)
imports.Append(g.NestedObject.AssociatedExternalType.Imports())

return imports
}
Expand Down
13 changes: 6 additions & 7 deletions internal/datasource_generate/single_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import (
type GeneratorSingleNestedAttribute struct {
schema.SingleNestedAttribute

AssociatedExternalType *generatorschema.AssocExtType
Attributes generatorschema.GeneratorAttributes
// The "specschema" types are used instead of the types within the attribute
// because support for extracting custom import information is required.
AssociatedExternalType *specschema.AssociatedExternalType
Attributes generatorschema.GeneratorAttributes
CustomType *specschema.CustomType
Validators []specschema.ObjectValidator
CustomType *specschema.CustomType
Validators []specschema.ObjectValidator
}

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

func (g GeneratorSingleNestedAttribute) AttrType() attr.Type {
Expand All @@ -55,8 +55,7 @@ func (g GeneratorSingleNestedAttribute) Imports() *generatorschema.Imports {
// TODO: This should only be added if model object helper functions are being generated.
imports.Append(generatorschema.AttrImports())

assocExtTypeImports := generatorschema.AssociatedExternalTypeImports(g.AssociatedExternalType)
imports.Append(assocExtTypeImports)
imports.Append(g.AssociatedExternalType.Imports())

return imports
}
Expand Down
15 changes: 7 additions & 8 deletions internal/datasource_generate/single_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ import (
type GeneratorSingleNestedBlock struct {
schema.SingleNestedBlock

// The "specschema" types are used instead of the types within the attribute
// because support for extracting custom import information is required.
AssociatedExternalType *specschema.AssociatedExternalType
AssociatedExternalType *generatorschema.AssocExtType
Attributes generatorschema.GeneratorAttributes
Blocks generatorschema.GeneratorBlocks
CustomType *specschema.CustomType
Validators []specschema.ObjectValidator
// The "specschema" types are used instead of the types within the attribute
// because support for extracting custom import information is required.
CustomType *specschema.CustomType
Validators []specschema.ObjectValidator
}

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

func (g GeneratorSingleNestedBlock) AttrType() attr.Type {
Expand Down Expand Up @@ -60,8 +60,7 @@ func (g GeneratorSingleNestedBlock) Imports() *generatorschema.Imports {
// TODO: This should only be added if model object helper functions are being generated.
imports.Append(generatorschema.AttrImports())

assocExtTypeImports := generatorschema.AssociatedExternalTypeImports(g.AssociatedExternalType)
imports.Append(assocExtTypeImports)
imports.Append(g.AssociatedExternalType.Imports())

return imports
}
Expand Down
4 changes: 2 additions & 2 deletions internal/datasource_generate/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type GeneratorNestedAttributeObject struct {
Attributes schema.GeneratorAttributes

AssociatedExternalType *specschema.AssociatedExternalType
AssociatedExternalType *schema.AssocExtType
CustomType *specschema.CustomType
Validators []specschema.ObjectValidator
}
Expand All @@ -21,7 +21,7 @@ type GeneratorNestedBlockObject struct {
Attributes schema.GeneratorAttributes
Blocks schema.GeneratorBlocks

AssociatedExternalType *specschema.AssociatedExternalType
AssociatedExternalType *schema.AssocExtType
CustomType *specschema.CustomType
Validators []specschema.ObjectValidator
}
Loading

0 comments on commit 05abb31

Please sign in to comment.