-
Notifications
You must be signed in to change notification settings - Fork 175
Description
I have been using the valid types feature and found it very convenient.
On the server side, it is nice that I can handle a validated message as a narrowed type.
Then I thought that the same kind of narrowing would also be useful on the client side, for validated response messages.
However, fields that have (google.api.field_behavior) = OUTPUT_ONLY are difficult to deal with.
If I set (buf.validate.field).required = true, the request validation fails, so I cannot make them required, and because of that the client cannot know that those fields always exist in responses.
If there was an option to generate two valid types based on (google.api.field_behavior), it might solve this problem.
For example:
FooValidInput: excludes fields with(google.api.field_behavior) = OUTPUT_ONLYFooValidOutput: includes those fields, and maybe treats(google.api.field_behavior) = INPUT_ONLYin the opposite way
Then both sides could validate and use narrowed types without duplicating .proto messages.
If this change happens, protovalidate would also need a related feature to generate two kinds of validators for input and output.
I understand that (google.api.field_behavior) is a Google annotation, and maybe Buf does not want to handle it directly.
But if there is any other way to solve this problem, it would be very helpful.