[#872] changed the schema required validator to be optional for auth collections

This commit is contained in:
Gani Georgiev committed 2022-11-16 15:13:04 +02:00
1 parent 4528f075dc
commit 6e9cf986c5
45 files changed
+1166 -445

No files matched your search

+14
View File
@@ -116,6 +116,7 @@ func (form *CollectionUpsert) Validate() error {
// validates using the type's own validation rules + some collection's specific
validation.Field(
&form.Schema,
validation.By(form.checkMinSchemaFields),
validation.By(form.ensureNoSystemFieldsChange),
validation.By(form.ensureNoFieldsTypeChange),
validation.By(form.ensureExistingRelationCollectionId),
@@ -255,6 +256,19 @@ func (form *CollectionUpsert) ensureNoAuthFieldName(value any) error {
return nil
}
func (form *CollectionUpsert) checkMinSchemaFields(value any) error {
if form.Type == models.CollectionTypeAuth {
return nil // auth collections doesn't require having additional schema fields
}
v, ok := value.(schema.Schema)
if !ok || len(v.Fields()) == 0 {
return validation.ErrRequired
}
return nil
}
func (form *CollectionUpsert) ensureNoSystemFieldsChange(value any) error {
v, _ := value.(schema.Schema)