kin-openapi
kin-openapi copied to clipboard
Consider adding context to Validator Middleware's ErrFunc and LogFunc functions
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.
Please go ahead with the first proposition (the breaking change)