Skip to content

Commit

Permalink
removed prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
shireesh-illumio committed Dec 12, 2024
1 parent 62f1767 commit fd2828a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions api/protogen/protogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func GenerateGRPCAPISpec(dst io.Writer, src schema.Schema, tagger *apiSpecTagger
for _, attrName := range attrNames {
attrSchema := resource.Schema.Attributes[attrName]

repeated, t, msg, err := terraformAttributeTypeToProtoType(attrName, attrSchema.GetType(), resourceName)
repeated, t, msg, err := terraformAttributeTypeToProtoType(attrName, attrSchema.GetType())
if err != nil {
return fmt.Errorf("failed to parse field %s in resource %s: %w", attrName, resourceMessageName, err)
}
Expand Down Expand Up @@ -249,7 +249,7 @@ func GenerateGRPCAPISpec(dst io.Writer, src schema.Schema, tagger *apiSpecTagger
}

// terraformAttributeTypeToProtoType converts a Terraform attribute type into the corresponding Protocol Buffer type, and optionally additional Protocol Buffer messages that represent nested types.
func terraformAttributeTypeToProtoType(attrName string, attrType attr.Type, prefix string) (repeated bool, protoType string, messages *message, err error) {
func terraformAttributeTypeToProtoType(attrName string, attrType attr.Type) (repeated bool, protoType string, messages *message, err error) {
switch v := attrType.(type) {
case basetypes.BoolType:
return false, "bool", nil, nil
Expand All @@ -260,7 +260,7 @@ func terraformAttributeTypeToProtoType(attrName string, attrType attr.Type, pref
case basetypes.StringType:
return false, "string", nil, nil
case types.ListType:
toProtoType, s, m, err := terraformRepeatedAttributeTypeToProtoType(attrName, v.ElementType(), prefix)
toProtoType, s, m, err := terraformRepeatedAttributeTypeToProtoType(attrName, v.ElementType())
if err != nil {
return false, "", nil, err
}
Expand All @@ -272,25 +272,25 @@ func terraformAttributeTypeToProtoType(attrName string, attrType attr.Type, pref

return toProtoType, s, m, nil
case types.SetType:
return terraformRepeatedAttributeTypeToProtoType(attrName, v.ElementType(), prefix)
return terraformRepeatedAttributeTypeToProtoType(attrName, v.ElementType())
case types.ObjectType:
return terraformObjectAttributeTypeToProtoType(attrName, v.AttrTypes, prefix)
return terraformObjectAttributeTypeToProtoType(attrName, v.AttrTypes)

default:
return false, "", nil, fmt.Errorf("unsupported Terraform type: %s", attrType.String())
}
}

// Converts a Terraform object attribute to a Protocol Buffer message type.
func terraformObjectAttributeTypeToProtoType(attrName string, attrTypes map[string]attr.Type, prefix string) (repeated bool, protoType string, messages *message, err error) {
func terraformObjectAttributeTypeToProtoType(attrName string, attrTypes map[string]attr.Type) (repeated bool, protoType string, messages *message, err error) {
messageName := schema.ProtoMessageName(attrName)
newMessage := &message{
Name: messageName,
Fields: []field{},
}

for name, attrType := range attrTypes {
repeated, t, msg, err := terraformAttributeTypeToProtoType(name, attrType, schema.ProtoMessageName(prefix)+schema.ProtoMessageName(messageName))
repeated, t, msg, err := terraformAttributeTypeToProtoType(name, attrType)
if err != nil {
return false, "", nil, fmt.Errorf("failed to parse field %s in object %s: %w", name, attrName, err)
}
Expand All @@ -314,8 +314,8 @@ func terraformObjectAttributeTypeToProtoType(attrName string, attrTypes map[stri
return false, messageName, newMessage, nil
}

func terraformRepeatedAttributeTypeToProtoType(attrName string, elementType attr.Type, prefix string) (repeated bool, protoType string, messages *message, err error) {
elemRepeated, elemProtoType, elemMessage, err := terraformAttributeTypeToProtoType(attrName, elementType, prefix)
func terraformRepeatedAttributeTypeToProtoType(attrName string, elementType attr.Type) (repeated bool, protoType string, messages *message, err error) {
elemRepeated, elemProtoType, elemMessage, err := terraformAttributeTypeToProtoType(attrName, elementType)

switch {
case err != nil:
Expand Down

0 comments on commit fd2828a

Please sign in to comment.