Skip to content

Commit

Permalink
Handling nested primitives that have an associated external type (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Oct 19, 2023
1 parent 99e04d2 commit 98d9c00
Show file tree
Hide file tree
Showing 43 changed files with 1,265 additions and 68 deletions.
42 changes: 42 additions & 0 deletions internal/datasource_generate/bool_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,45 @@ func (g GeneratorBoolAttribute) ToFromFunctions(name string) ([]byte, error) {

return b, nil
}

// AttrType returns a string representation of a basetypes.BoolTypable type.
func (g GeneratorBoolAttribute) AttrType(name generatorschema.FrameworkIdentifier) string {
if g.AssociatedExternalType != nil {
return fmt.Sprintf("%sType{}", name.ToPascalCase())
}

return "basetypes.BoolType{}"
}

// AttrValue returns a string representation of a basetypes.BoolValuable type.
func (g GeneratorBoolAttribute) AttrValue(name generatorschema.FrameworkIdentifier) string {
if g.AssociatedExternalType != nil {
return fmt.Sprintf("%sValue", name.ToPascalCase())
}

return "basetypes.BoolValue"
}

func (g GeneratorBoolAttribute) To() generatorschema.ToFromConversion {
if g.AssociatedExternalType != nil {
return generatorschema.ToFromConversion{
AssocExtType: g.AssociatedExternalType,
}
}

return generatorschema.ToFromConversion{
Default: "ValueBoolPointer",
}
}

func (g GeneratorBoolAttribute) From() generatorschema.ToFromConversion {
if g.AssociatedExternalType != nil {
return generatorschema.ToFromConversion{
AssocExtType: g.AssociatedExternalType,
}
}

return generatorschema.ToFromConversion{
Default: "BoolPointerValue",
}
}
42 changes: 42 additions & 0 deletions internal/datasource_generate/float64_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,45 @@ func (g GeneratorFloat64Attribute) ToFromFunctions(name string) ([]byte, error)

return b, nil
}

// AttrType returns a string representation of a basetypes.Float64Typable type.
func (g GeneratorFloat64Attribute) AttrType(name generatorschema.FrameworkIdentifier) string {
if g.AssociatedExternalType != nil {
return fmt.Sprintf("%sType{}", name.ToPascalCase())
}

return "basetypes.Float64Type{}"
}

// AttrValue returns a string representation of a basetypes.Float64Valuable type.
func (g GeneratorFloat64Attribute) AttrValue(name generatorschema.FrameworkIdentifier) string {
if g.AssociatedExternalType != nil {
return fmt.Sprintf("%sValue", name.ToPascalCase())
}

return "basetypes.Float64Value"
}

func (g GeneratorFloat64Attribute) To() generatorschema.ToFromConversion {
if g.AssociatedExternalType != nil {
return generatorschema.ToFromConversion{
AssocExtType: g.AssociatedExternalType,
}
}

return generatorschema.ToFromConversion{
Default: "ValueFloat64Pointer",
}
}

func (g GeneratorFloat64Attribute) From() generatorschema.ToFromConversion {
if g.AssociatedExternalType != nil {
return generatorschema.ToFromConversion{
AssocExtType: g.AssociatedExternalType,
}
}

return generatorschema.ToFromConversion{
Default: "Float64PointerValue",
}
}
42 changes: 42 additions & 0 deletions internal/datasource_generate/int64_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,45 @@ func (g GeneratorInt64Attribute) ToFromFunctions(name string) ([]byte, error) {

return b, nil
}

// AttrType returns a string representation of a basetypes.Int64Typable type.
func (g GeneratorInt64Attribute) AttrType(name generatorschema.FrameworkIdentifier) string {
if g.AssociatedExternalType != nil {
return fmt.Sprintf("%sType{}", name.ToPascalCase())
}

return "basetypes.Int64Type{}"
}

// AttrValue returns a string representation of a basetypes.Int64Valuable type.
func (g GeneratorInt64Attribute) AttrValue(name generatorschema.FrameworkIdentifier) string {
if g.AssociatedExternalType != nil {
return fmt.Sprintf("%sValue", name.ToPascalCase())
}

return "basetypes.Int64Value"
}

func (g GeneratorInt64Attribute) To() generatorschema.ToFromConversion {
if g.AssociatedExternalType != nil {
return generatorschema.ToFromConversion{
AssocExtType: g.AssociatedExternalType,
}
}

return generatorschema.ToFromConversion{
Default: "ValueInt64Pointer",
}
}

func (g GeneratorInt64Attribute) From() generatorschema.ToFromConversion {
if g.AssociatedExternalType != nil {
return generatorschema.ToFromConversion{
AssocExtType: g.AssociatedExternalType,
}
}

return generatorschema.ToFromConversion{
Default: "Int64PointerValue",
}
}
22 changes: 21 additions & 1 deletion internal/datasource_generate/list_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func (g GeneratorListNestedAttribute) ToFromFunctions(name string) ([]byte, erro
return nil, nil
}

var buf bytes.Buffer

toFuncs := g.NestedObject.Attributes.ToFuncs()

fromFuncs := g.NestedObject.Attributes.FromFuncs()
Expand All @@ -221,5 +223,23 @@ func (g GeneratorListNestedAttribute) ToFromFunctions(name string) ([]byte, erro
return nil, err
}

return b, nil
buf.Write(b)

attributeKeys := g.NestedObject.Attributes.SortedKeys()

// Recursively call ToFromFunctions() for each attribute that implements
// ToFrom interface.
for _, k := range attributeKeys {
if c, ok := g.NestedObject.Attributes[k].(generatorschema.ToFrom); ok {
b, err := c.ToFromFunctions(k)

if err != nil {
return nil, err
}

buf.Write(b)
}
}

return buf.Bytes(), nil
}
22 changes: 21 additions & 1 deletion internal/datasource_generate/list_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ func (g GeneratorListNestedBlock) ToFromFunctions(name string) ([]byte, error) {
return nil, nil
}

var buf bytes.Buffer

toFuncs := g.NestedObject.Attributes.ToFuncs()

fromFuncs := g.NestedObject.Attributes.FromFuncs()
Expand All @@ -299,5 +301,23 @@ func (g GeneratorListNestedBlock) ToFromFunctions(name string) ([]byte, error) {
return nil, err
}

return b, nil
buf.Write(b)

attributeKeys := g.NestedObject.Attributes.SortedKeys()

// Recursively call ToFromFunctions() for each attribute that implements
// ToFrom interface.
for _, k := range attributeKeys {
if c, ok := g.NestedObject.Attributes[k].(generatorschema.ToFrom); ok {
b, err := c.ToFromFunctions(k)

if err != nil {
return nil, err
}

buf.Write(b)
}
}

return buf.Bytes(), nil
}
22 changes: 21 additions & 1 deletion internal/datasource_generate/map_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func (g GeneratorMapNestedAttribute) ToFromFunctions(name string) ([]byte, error
return nil, nil
}

var buf bytes.Buffer

toFuncs := g.NestedObject.Attributes.ToFuncs()

fromFuncs := g.NestedObject.Attributes.FromFuncs()
Expand All @@ -221,5 +223,23 @@ func (g GeneratorMapNestedAttribute) ToFromFunctions(name string) ([]byte, error
return nil, err
}

return b, nil
buf.Write(b)

attributeKeys := g.NestedObject.Attributes.SortedKeys()

// Recursively call ToFromFunctions() for each attribute that implements
// ToFrom interface.
for _, k := range attributeKeys {
if c, ok := g.NestedObject.Attributes[k].(generatorschema.ToFrom); ok {
b, err := c.ToFromFunctions(k)

if err != nil {
return nil, err
}

buf.Write(b)
}
}

return buf.Bytes(), nil
}
42 changes: 42 additions & 0 deletions internal/datasource_generate/number_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,45 @@ func (g GeneratorNumberAttribute) ToFromFunctions(name string) ([]byte, error) {

return b, nil
}

// AttrType returns a string representation of a basetypes.NumberTypable type.
func (g GeneratorNumberAttribute) AttrType(name generatorschema.FrameworkIdentifier) string {
if g.AssociatedExternalType != nil {
return fmt.Sprintf("%sType{}", name.ToPascalCase())
}

return "basetypes.NumberType{}"
}

// AttrValue returns a string representation of a basetypes.NumberValuable type.
func (g GeneratorNumberAttribute) AttrValue(name generatorschema.FrameworkIdentifier) string {
if g.AssociatedExternalType != nil {
return fmt.Sprintf("%sValue", name.ToPascalCase())
}

return "basetypes.NumberValue"
}

func (g GeneratorNumberAttribute) To() generatorschema.ToFromConversion {
if g.AssociatedExternalType != nil {
return generatorschema.ToFromConversion{
AssocExtType: g.AssociatedExternalType,
}
}

return generatorschema.ToFromConversion{
Default: "ValueBigFloat",
}
}

func (g GeneratorNumberAttribute) From() generatorschema.ToFromConversion {
if g.AssociatedExternalType != nil {
return generatorschema.ToFromConversion{
AssocExtType: g.AssociatedExternalType,
}
}

return generatorschema.ToFromConversion{
Default: "NumberValue",
}
}
22 changes: 21 additions & 1 deletion internal/datasource_generate/set_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ func (g GeneratorSetNestedAttribute) ToFromFunctions(name string) ([]byte, error
return nil, nil
}

var buf bytes.Buffer

toFuncs := g.NestedObject.Attributes.ToFuncs()

fromFuncs := g.NestedObject.Attributes.FromFuncs()
Expand All @@ -221,5 +223,23 @@ func (g GeneratorSetNestedAttribute) ToFromFunctions(name string) ([]byte, error
return nil, err
}

return b, nil
buf.Write(b)

attributeKeys := g.NestedObject.Attributes.SortedKeys()

// Recursively call ToFromFunctions() for each attribute that implements
// ToFrom interface.
for _, k := range attributeKeys {
if c, ok := g.NestedObject.Attributes[k].(generatorschema.ToFrom); ok {
b, err := c.ToFromFunctions(k)

if err != nil {
return nil, err
}

buf.Write(b)
}
}

return buf.Bytes(), nil
}
22 changes: 21 additions & 1 deletion internal/datasource_generate/set_nested_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ func (g GeneratorSetNestedBlock) ToFromFunctions(name string) ([]byte, error) {
return nil, nil
}

var buf bytes.Buffer

toFuncs := g.NestedObject.Attributes.ToFuncs()

fromFuncs := g.NestedObject.Attributes.FromFuncs()
Expand All @@ -299,5 +301,23 @@ func (g GeneratorSetNestedBlock) ToFromFunctions(name string) ([]byte, error) {
return nil, err
}

return b, nil
buf.Write(b)

attributeKeys := g.NestedObject.Attributes.SortedKeys()

// Recursively call ToFromFunctions() for each attribute that implements
// ToFrom interface.
for _, k := range attributeKeys {
if c, ok := g.NestedObject.Attributes[k].(generatorschema.ToFrom); ok {
b, err := c.ToFromFunctions(k)

if err != nil {
return nil, err
}

buf.Write(b)
}
}

return buf.Bytes(), nil
}
22 changes: 21 additions & 1 deletion internal/datasource_generate/single_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ func (g GeneratorSingleNestedAttribute) ToFromFunctions(name string) ([]byte, er
return nil, nil
}

var buf bytes.Buffer

toFuncs := g.Attributes.ToFuncs()

fromFuncs := g.Attributes.FromFuncs()
Expand All @@ -224,5 +226,23 @@ func (g GeneratorSingleNestedAttribute) ToFromFunctions(name string) ([]byte, er
return nil, err
}

return b, nil
buf.Write(b)

attributeKeys := g.Attributes.SortedKeys()

// Recursively call ToFromFunctions() for each attribute that implements
// ToFrom interface.
for _, k := range attributeKeys {
if c, ok := g.Attributes[k].(generatorschema.ToFrom); ok {
b, err := c.ToFromFunctions(k)

if err != nil {
return nil, err
}

buf.Write(b)
}
}

return buf.Bytes(), nil
}
Loading

0 comments on commit 98d9c00

Please sign in to comment.