feat: add before/after validation hooks for request and response bodies#1161
Open
ClearEyesFullHearts wants to merge 1 commit intocdimascio:masterfrom
Open
feat: add before/after validation hooks for request and response bodies#1161ClearEyesFullHearts wants to merge 1 commit intocdimascio:masterfrom
ClearEyesFullHearts wants to merge 1 commit intocdimascio:masterfrom
Conversation
Introduce two new extension points in `OpenApiValidatorOpts`: - `beforeRequestBodyValidation`: handlers keyed by name, invoked (via `x-eov-before-request-body-validation` on an operation) before the request body is validated, allowing mutations or enrichment of `req.body` and access to the operation schema. - `afterResponseBodyValidation`: handlers keyed by name, invoked (via `x-eov-after-response-body-validation` on an operation) after the response body passes validation, allowing transformation of the outgoing body before it is sent. Both handler types support async execution. The response hook uses `mung.jsonAsync` when handlers are registered. Corresponding types (`BeforeRequestBodyValidationHandler/Handlers` and `AfterResponseBodyValidationHandler/Handlers`) are exported from `framework/types`. Full integration tests are added covering: hook invocation, body mutation, schema capture, skipping routes without the extension field, async handlers, and error handling for missing or failing hooks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce two new extension points in
OpenApiValidatorOpts:beforeRequestBodyValidation: handlers keyed by name, invoked (viax-eov-before-request-body-validationon an operation) before the request body is validated, allowing mutations or enrichment ofreq.bodyand access to the operation schema.afterResponseBodyValidation: handlers keyed by name, invoked (viax-eov-after-response-body-validationon an operation) after the response body passes validation, allowing transformation of the outgoing body before it is sent.Both handler types support async execution. The response hook uses
mung.jsonAsyncwhen handlers are registered. Corresponding types (BeforeRequestBodyValidationHandler/HandlersandAfterResponseBodyValidationHandler/Handlers) are exported fromframework/types.Full integration tests are added covering: hook invocation, body mutation, schema capture, skipping routes without the extension field, async handlers, and error handling for missing or failing hooks.