Skip to content

Support for middleware execution after validateSecurity but before operationHandlers #1042

@iva666ka

Description

@iva666ka

Is your feature request related to a problem? Please describe.

I am using express-openapi-validator with the validateSecurity and operationHandlers options. In validateSecurity, I pass functions that decode the JWT token, validate it, and add information from the token payload to req. In operationHandlers, I specify the path to the files where functions with the same names as those defined in operationId in the openapi.yaml file are located.

I am trying to figure out how to add middleware that applies after the validateSecurity functions but before the operationHandlers, which route the requests. However, it seems that this is not possible. The only workaround I can see is passing a resolver function in OperationHandlerOptions, but this feels like a hack. This approach combines two separate concerns—route creation and middleware application into one concrete route, making it less intuitive.

Describe the solution you'd like

It would be great if there were an optional parameter, something like postAuthMiddlewares or postValidateSecurityMiddlewares, which would accept an array of RequestHandler and be applied after validateSecurity but before the routing stage handled by operationHandlers.

Describe alternatives you've considered

Additional context

express-openapi-validator version: 5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions