in pkg/schemaconv/smd.go [185:231]
func makeUnions(extensions map[string]interface{}) ([]schema.Union, error) {
schemaUnions := []schema.Union{}
if iunions, ok := extensions["x-kubernetes-unions"]; ok {
unions, ok := iunions.([]interface{})
if !ok {
return nil, fmt.Errorf(`"x-kubernetes-unions" should be a list, got %#v`, unions)
}
for _, iunion := range unions {
union, ok := iunion.(map[interface{}]interface{})
if !ok {
return nil, fmt.Errorf(`"x-kubernetes-unions" items should be a map of string to unions, got %#v`, iunion)
}
unionMap := map[string]interface{}{}
for k, v := range union {
key, ok := k.(string)
if !ok {
return nil, fmt.Errorf(`"x-kubernetes-unions" has non-string key: %#v`, k)
}
unionMap[key] = v
}
schemaUnion, err := makeUnion(unionMap)
if err != nil {
return nil, err
}
schemaUnions = append(schemaUnions, schemaUnion)
}
}
// Make sure we have no overlap between unions
fs := map[string]struct{}{}
for _, u := range schemaUnions {
if u.Discriminator != nil {
if _, ok := fs[*u.Discriminator]; ok {
return nil, fmt.Errorf("%v field appears multiple times in unions", *u.Discriminator)
}
fs[*u.Discriminator] = struct{}{}
}
for _, f := range u.Fields {
if _, ok := fs[f.FieldName]; ok {
return nil, fmt.Errorf("%v field appears multiple times in unions", f.FieldName)
}
fs[f.FieldName] = struct{}{}
}
}
return schemaUnions, nil
}