Documentation
¶
Overview ¶
Package schemagen provides Terraform schema generation.
Example ¶
package main import ( "fmt" "reflect" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/nitrado/tfconv/schemagen" ) func main() { type TestObject struct { Test string `json:"test"` } docs := func(obj any, sf reflect.StructField) string { // Return the documentation for the struct field. return "" } customize := func(obj any, sf *reflect.StructField, typ reflect.Type, s *schema.Schema) (string, reflect.Kind, bool) { // Customize the schema output for a sctruct field. return "", typ.Kind(), true } gen := schemagen.New(docs, customize, "json") s, err := gen.Struct(TestObject{}) if err != nil { panic(err) } fmt.Printf("%s", s) }
Output: map[test:{ Type: schema.TypeString, }]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CustomizerFunc ¶
type CustomizerFunc = func(obj any, sf *reflect.StructField, typ reflect.Type, s *schema.Schema) (string, reflect.Kind, bool)
CustomizerFunc is a function used to customize a schema. It returns an optional function name, the amended kind and a bool determining if the field should be skipped.
type DocsFunc ¶
type DocsFunc = func(obj any, sf reflect.StructField) string
DocsFunc is a function that returns the documentation for a struct field.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator generates Terraform schemas.
func New ¶
func New(docsFn DocsFunc, customizerFn CustomizerFunc, tag string) *Generator
New returns a schema generator.
func NewWithName ¶ added in v1.2.0
func NewWithName(docsFn DocsFunc, customizerFn CustomizerFunc, nameFn NameFunc, tag string) *Generator
NewWithName returns a schema generator with the given nameFn.
func (*Generator) ResolveName ¶
func (g *Generator) ResolveName(sf reflect.StructField) string
ResolveName resolves the name of a field.
Click to show internal directories.
Click to hide internal directories.