-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support validation of responses in Interceptor #28
Comments
@mattdowdell, response validation has come up more than once before, so we'll keep this on the backlog. If/when we add such an option, it will be simpler -- just a simple Normally, I might not propose that sort of change (changing a signature to accept an interface instead of the existing concrete type), since it is not backwards-compatible. However, the github.com/bufbuild/protovalidate-go repo has recently made that same breaking change already, so when the next version is released and incorporated into this module, a backwards-incompatible change is inevitable. |
@jhump thanks for the thoughtful response. Regarding your proposal to wrap the validator for error transformation, I'm a little confused how you would differentiate between a request a response message. I can see the current interceptor behaviour is to reject invalid requests with an InvalidArgument status code, which I think is the correct choice. But I don't see anything to programmatically hook off in the Protobuf message that would let me replace the error with an Internal status code. I also don't quite see why the validator would be responsible for sending the error status when that logic lies in the interceptor here. It feels muddled to move that logic to a lower level. I might rely on the message name's suffix to only target responses, but such suffixes are by convention and only enforced if using buf lint's RPC_RESPONSE_STANDARD_NAME. To me, using that convention feels like a little too large an assumption for this. I wonder if I'm suffering from a lack of imagination - did you have something else in mind for implementing this feature? |
Ah, you are right. The objective behind the suggested simplification would be to minimize the API surface area, eliding anything that isn't strictly necessary. If, for example, this could be done in a different way that composes with the validation interceptor, instead of having to push it into the validation interceptor, that is what we'd prefer. We'll need to think about this a little more. |
As it stands, it appears that only requests are validated by the
Interceptor
implementation, i.e. when the client sends the request, when the handler receives the request. In the past, I've found it useful to also validate the response as a sanity check and to protect clients from an obviously broken implementation.Would this be a feature you'd consider?
As a rough example of what I had in mind:
The text was updated successfully, but these errors were encountered: