grpc-ecosystem / grpc-gateway

gRPC to JSON proxy generator following the gRPC HTTP spec
https://grpc-ecosystem.github.io/grpc-gateway/
BSD 3-Clause "New" or "Revised" License
18.18k stars 2.23k forks source link

feature request: opt-out fieldmask behaviour in patch #839

Closed glerchundi closed 5 years ago

glerchundi commented 5 years ago

I would like to get rid of this fieldmask related thingy on generated code because we're already generating this on another step.

Would you be open to opt-out this by hinting the generator so that it can exclude that piece from generated code?

WDYT?

/cc @razamiDev @johanbrandhorst

In case you were interested we're generating a metadata code based on proto extensions that define which field is 'updateable' and which isn't (by default it's updateable).

message AccessPoint {
    string name = 1 [(myorg.updatable) = false];

    // Display name.
    string display_name = 2;
}

This would generate:

[...]
var _AccessPoint_Updateables = []string{
    "display_name",
}

var _AccessPoint_Updateables_Lookup = map[string]bool{
    "name": false,
    "display_name": true,
}

func (m *AccessPoint) Updateables() []string {
    return _AccessPoint_Updateables
}

func (m *AccessPoint) IsUpdateable(path string) bool {
    updateable, ok := _AccessPoint_Updateables_Lookup[path]
    if !ok {
        return true
    }

    return updateable
}
[...]
johanbrandhorst commented 5 years ago

Sure that seems reasonable, I guess it would have to be a runtime parameter?

On another note, it seems the official advice for disallowing updates is to mark the field "Output only" in a comment. This is not enforced in code, of course.

glerchundi commented 5 years ago

Sure that seems reasonable, I guess it would have to be a runtime parameter?

If you don't mind I prefer to avoid the generated code.

On another note, it seems the official advice for disallowing updates is to mark the field "Output only" in a comment. This is not enforced in code, of course.

Yeah, but we found some (very) rare cases where fields that aren't going to be outputted but can be updated. For example an Account where the password is never printed to the outside but is considered as updateable.

Thanks anyway!