Skip to content

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

@nsp

Description

@nsp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions