kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

Consider adding context to Validator Middleware's ErrFunc and LogFunc functions

Open nsp opened this issue 3 years ago • 1 comments

This would be a breaking change, but for us, a good thing if these openapi3filter/middleware.go's types were instead

// ErrFunc handles errors that may occur during validation.
type ErrFunc func(ctx context.Context, w http.ResponseWriter, status int, code ErrCode, err error)

// LogFunc handles log messages that may occur during validation.
type LogFunc func(ctx context.Context, message string, err error)

And invoked by the middleware with r.Context(). This way, the logging and error handling functions can access important info from the request context, like tracingIDs, requestIDs, deadline information, etc.

It might not be a breaking change if additional handler functions are added (ErrWithContextFunc and LogWithContextFunc?) for additional complexity.

If one of these approaches is acceptable, I can contribute a MR.

nsp avatar Jan 06 '22 01:01 nsp

Please go ahead with the first proposition (the breaking change)

fenollp avatar Feb 23 '22 09:02 fenollp