func (u *union) setDiscriminator(value string) []error {
	errors := []error{}
	if u.discriminator != "" {
		errors = append(errors, fmt.Errorf("at least two discriminators found: %v and %v", value, u.discriminator))
	}
	u.discriminator = value
	return errors
}
Sets the discriminator if it's not set yet, otherwise return an error
package generators
import (
	"fmt"
	"sort"
	"k8s.io/gengo/types"
)
const tagUnionMember = "union"
const tagUnionDeprecated = "unionDeprecated"
const tagUnionDiscriminator = "unionDiscriminator"
type union struct {
	discriminator         string
	fieldsToDiscriminated map[string]string
}
func (u *union) emit(g openAPITypeWriter) {
	if u == nil {
		return
	}
	g.Do("map[string]interface{}{\n", nil)
	if u.discriminator != "" {
		g.Do("\"discriminator\": \"$.$\",\n", u.discriminator)
	}
	g.Do("\"fields-to-discriminateBy\": map[string]interface{}{\n", nil)
	keys := []string{}
	for field := range u.fieldsToDiscriminated {
		keys = append(keys, field)
	}
	sort.Strings(keys)
	for _, field := range keys {
		g.Do("\"$.$\": ", field)
		g.Do("\"$.$\",\n", u.fieldsToDiscriminated[field])
	}
	g.Do("},\n", nil)
	g.Do("},\n", nil)
}