[#872] changed the schema required validator to be optional for auth collections
This commit is contained in:
@@ -133,13 +133,9 @@ func (s *Schema) AddField(newField *SchemaField) {
|
||||
// Internally calls each individual field's validator and additionally
|
||||
// checks for invalid renamed fields and field name duplications.
|
||||
func (s Schema) Validate() error {
|
||||
return validation.Validate(&s.fields, validation.Required, validation.By(func(value any) error {
|
||||
return validation.Validate(&s.fields, validation.By(func(value any) error {
|
||||
fields := s.fields // use directly the schema value to avoid unnecessary interface casting
|
||||
|
||||
if len(fields) == 0 {
|
||||
return validation.NewError("validation_invalid_schema", "Invalid schema format.")
|
||||
}
|
||||
|
||||
ids := []string{}
|
||||
names := []string{}
|
||||
for i, field := range fields {
|
||||
@@ -204,8 +200,9 @@ func (s *Schema) UnmarshalJSON(data []byte) error {
|
||||
|
||||
// Value implements the [driver.Valuer] interface.
|
||||
func (s Schema) Value() (driver.Value, error) {
|
||||
if len(s.fields) == 0 {
|
||||
return nil, nil
|
||||
if s.fields == nil {
|
||||
// initialize an empty slice to ensure that `[]` is returned
|
||||
s.fields = []*SchemaField{}
|
||||
}
|
||||
|
||||
data, err := json.Marshal(s.fields)
|
||||
|
||||
@@ -215,7 +215,7 @@ func TestSchemaValidate(t *testing.T) {
|
||||
// no fields
|
||||
{
|
||||
schema.NewSchema(),
|
||||
true,
|
||||
false,
|
||||
},
|
||||
// duplicated field ids
|
||||
{
|
||||
@@ -342,7 +342,7 @@ func TestSchemaValue(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v1 != nil {
|
||||
if v1 != "[]" {
|
||||
t.Fatalf("Expected nil, got %v", v1)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user