func (objectType *ObjectType) AsType(codeGenerationContext *CodeGenerationContext) dst.Expr {
	var fields []*dst.Field
	for _, f := range objectType.EmbeddedProperties() {
		fields = append(fields, f.AsField(codeGenerationContext))
	}
	for _, f := range objectType.Properties() {
		fields = append(fields, f.AsField(codeGenerationContext))
	}
	if len(fields) > 0 {
		fields[0].Decs.Before = dst.NewLine
	}
	return &dst.StructType{
		Fields: &dst.FieldList{
			List: fields,
		},
	}
}
AsType implements Type for ObjectType
package astmodel
import (
	"go/token"
	"sort"
	"strings"
	"github.com/Azure/k8s-infra/hack/generator/pkg/astbuilder"
	"github.com/dave/dst"
	"github.com/pkg/errors"
)
type ObjectType struct {
	embedded   map[TypeName]*PropertyDefinition
	properties map[PropertyName]*PropertyDefinition
	functions  map[string]Function
	testcases  map[string]TestCase
	InterfaceImplementer
}
var EmptyObjectType = NewObjectType()
var _ Type = &ObjectType{}
var _ PropertyContainer = &ObjectType{}
var _ FunctionContainer = &ObjectType{}
func NewObjectType() *ObjectType {
	return &ObjectType{
		embedded:             make(map[TypeName]*PropertyDefinition),
		properties:           make(map[PropertyName]*PropertyDefinition),
		functions:            make(map[string]Function),
		testcases:            make(map[string]TestCase),
		InterfaceImplementer: MakeInterfaceImplementer(),
	}
}
func (objectType *ObjectType) AsDeclarations(codeGenerationContext *CodeGenerationContext, declContext DeclarationContext) []dst.Decl {
	declaration := &dst.GenDecl{
		Decs: dst.GenDeclDecorations{
			NodeDecs: dst.NodeDecs{
				Before: dst.EmptyLine,
				After:  dst.EmptyLine,
			},
		},
		Tok: token.TYPE,
		Specs: []dst.Spec{
			&dst.TypeSpec{
				Name: dst.NewIdent(declContext.Name.Name()),
				Type: objectType.AsType(codeGenerationContext),
			},
		},
	}
	astbuilder.AddWrappedComments(&declaration.Decs.Start, declContext.Description, 200)
	AddValidationComments(&declaration.Decs.Start, declContext.Validations)
	result := []dst.Decl{declaration}
	result = append(result, objectType.InterfaceImplementer.AsDeclarations(codeGenerationContext, declContext.Name, nil)...)
	result = append(result, objectType.generateMethodDecls(codeGenerationContext, declContext.Name)...)
	return result
}
func (objectType *ObjectType) generateMethodDecls(codeGenerationContext *CodeGenerationContext, typeName TypeName) []dst.Decl {
	var result []dst.Decl
	for _, f := range objectType.Functions() {
		funcDef := f.AsFunc(codeGenerationContext, typeName)
		result = append(result, funcDef)
	}
	return result
}
func defineField(fieldName string, fieldType dst.Expr, tag string) *dst.Field {
	result := &dst.Field{
		Type: fieldType,
		Tag:  astbuilder.TextLiteral(tag),
	}
	if fieldName != "" {
		result.Names = []*dst.Ident{dst.NewIdent(fieldName)}
	}
	return result
}
func (objectType *ObjectType) Properties() []*PropertyDefinition {
	var result []*PropertyDefinition
	for _, property := range objectType.properties {
		result = append(result, property)
	}
	sort.Slice(result, func(left int, right int) bool {
		return result[left].propertyName < result[right].propertyName
	})
	return result
}
func (objectType *ObjectType) Property(name PropertyName) (*PropertyDefinition, bool) {
	prop, ok := objectType.properties[name]
	return prop, ok
}
func (objectType *ObjectType) EmbeddedProperties() []*PropertyDefinition {
	var result []*PropertyDefinition
	for _, embedded := range objectType.embedded {
		result = append(result, embedded)
	}
	sort.Slice(result, func(left int, right int) bool {
		lTypeName, err := extractEmbeddedTypeName(result[left].PropertyType())
		if err != nil {
			panic(err)
		}
		rTypeName, err := extractEmbeddedTypeName(result[right].PropertyType())
		if err != nil {
			panic(err)
		}
		return lTypeName.Name() < rTypeName.Name()
	})
	return result
}
func (objectType *ObjectType) Functions() []Function {
	var functions []Function
	for _, f := range objectType.functions {
		functions = append(functions, f)
	}
	sort.Slice(functions, func(i int, j int) bool {
		return functions[i].Name() < functions[j].Name()
	})
	return functions
}
func (objectType *ObjectType) HasFunctionWithName(name string) bool {
	_, ok := objectType.functions[name]
	return ok
}