github.com/mineiros-io/terradoc@v0.0.9-0.20220711062319-018bd4ae81f5/internal/entities/type.go (about)

     1  package entities
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/mineiros-io/terradoc/internal/types"
     7  )
     8  
     9  // Type represents a variable or attribute type with its readme and Terraform type data
    10  type Type struct {
    11  	// TFType is the specific Terraform type definition for this type
    12  	TFType types.TerraformType `json:"type"`
    13  	// Label is an optional label for the TerraformType
    14  	Label string `json:"label"`
    15  	// Nested is an optional nested type definition
    16  	Nested *Type `json:"nested,omitempty"`
    17  }
    18  
    19  func (t Type) AsString() string {
    20  	switch {
    21  	case t.HasNestedType():
    22  		return fmt.Sprintf("%s(%s)", t.TFType.String(), t.Nested.AsString())
    23  	case t.Label != "":
    24  		return fmt.Sprintf("%s(%s)", t.TFType.String(), t.Label)
    25  	}
    26  
    27  	return t.TFType.String()
    28  }
    29  
    30  func (t Type) HasNestedType() bool {
    31  	return t.Nested != nil
    32  }