feat(schema)!: updates based on postgres testing (#20858)
This commit is contained in:
+2
-45
@@ -10,56 +10,13 @@ type ModuleSchema struct {
|
||||
|
||||
// Validate validates the module schema.
|
||||
func (s ModuleSchema) Validate() error {
|
||||
enumValueMap := map[string]map[string]bool{}
|
||||
for _, objType := range s.ObjectTypes {
|
||||
if err := objType.Validate(); err != nil {
|
||||
if err := objType.validate(enumValueMap); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// validate that shared enum types are consistent across object types
|
||||
enumValueMap := map[string]map[string]bool{}
|
||||
for _, objType := range s.ObjectTypes {
|
||||
for _, field := range objType.KeyFields {
|
||||
err := checkEnum(enumValueMap, field)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, field := range objType.ValueFields {
|
||||
err := checkEnum(enumValueMap, field)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkEnum(enumValueMap map[string]map[string]bool, field Field) error {
|
||||
if field.Kind != EnumKind {
|
||||
return nil
|
||||
}
|
||||
|
||||
enum := field.EnumDefinition
|
||||
|
||||
if existing, ok := enumValueMap[enum.Name]; ok {
|
||||
if len(existing) != len(enum.Values) {
|
||||
return fmt.Errorf("enum %q has different number of values in different object types", enum.Name)
|
||||
}
|
||||
|
||||
for _, value := range enum.Values {
|
||||
if !existing[value] {
|
||||
return fmt.Errorf("enum %q has different values in different object types", enum.Name)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
valueMap := map[string]bool{}
|
||||
for _, value := range enum.Values {
|
||||
valueMap[value] = true
|
||||
}
|
||||
enumValueMap[enum.Name] = valueMap
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user