mennanov / fieldmask-utils

Protobuf Field Mask Go utils
MIT License
229 stars 26 forks source link

Question: Is there a way to validate Mask fields are correct? #13

Closed dougdonohoe closed 3 years ago

dougdonohoe commented 3 years ago

I'd like to be able to easily catch bad paths (e.g., due to a typo or misconfiguration):

       paths := []string{
        "Person.FirstNaaaame",  // bad
        "Person.LastName",
    }
    // create mask
    mask, err := fu.MaskFromPaths(paths, namer)
        // desire
        err = fu.Validate(mask, someStruct}

Is there an existing way to validate that all paths refer to an actual field? I'm asking before I implement something to do this.

mennanov commented 3 years ago

Currently there is no mechanism that checks whether all the fields mentioned in the Mask exist in the source or the destination struct/map. If the field mentioned in the Mask does not exist in the source struct then it is just silently skipped (not copied).

If you need that check you'll have to implement it.