Skip to content

Commit

Permalink
Handle case of repeated external objects properly (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Calebjh authored Aug 22, 2022
1 parent 4cf9d82 commit 770604b
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 161 deletions.
21 changes: 21 additions & 0 deletions example/examplepb/example.pb.atlas.validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,27 @@ func validate_Object_User(ctx context.Context, r json.RawMessage, path string) (
return fmt.Errorf("invalid value for %q: expected array.", vArrPath)
}
case "timestamp":
case "some_friends":
if v[k] == nil {
continue
}
var vArr []json.RawMessage
vArrPath := runtime.JoinPath(path, k)
if err = json.Unmarshal(v[k], &vArr); err != nil {
return fmt.Errorf("invalid value for %q: expected array.", vArrPath)
}
validator, ok := interface{}(&external.ExternalUser{}).(interface {
AtlasValidateJSON(context.Context, json.RawMessage, string) error
})
if !ok {
continue
}
for i, vv := range vArr {
vvPath := fmt.Sprintf("%s.[%d]", vArrPath, i)
if err = validator.AtlasValidateJSON(ctx, vv, vvPath); err != nil {
return err
}
}
default:
if !allowUnknown {
return fmt.Errorf("unknown field %q.", runtime.JoinPath(path, k))
Expand Down
Loading

0 comments on commit 770604b

Please sign in to comment.