feat(validation): Add check for necessary keys in field json
This commit is contained in:
@@ -14,7 +14,23 @@ func ValidateField(field *Field) error {
|
||||
if err := ValidateHashAlgorithm(field); err != nil {
|
||||
return err
|
||||
}
|
||||
return ValidateFieldType(field)
|
||||
if err := ValidateAttributes(field); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ValidateFieldType(field); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateAttributes(field *Field) error {
|
||||
// Check if the field has keys that are necessary for the field
|
||||
for _, attribute := range requiredAttributes {
|
||||
if _, ok := map[string]any{field.Name: field.Type}[attribute]; !ok {
|
||||
return fmt.Errorf("attribute %s is required", attribute)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ValidateFieldType(field *Field) error {
|
||||
@@ -42,8 +58,7 @@ func ValidateHashAlgorithm(field *Field) error {
|
||||
|
||||
func (t *Table) Validate() error {
|
||||
for _, field := range t.Schema {
|
||||
err := ValidateField(&field)
|
||||
if err != nil {
|
||||
if err := ValidateField(&field); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user