Skip to content

feat: add before/after validation hooks for request and response bodies#1161

Open
ClearEyesFullHearts wants to merge 1 commit intocdimascio:masterfrom
ClearEyesFullHearts:feature-transform-hook
Open

feat: add before/after validation hooks for request and response bodies#1161
ClearEyesFullHearts wants to merge 1 commit intocdimascio:masterfrom
ClearEyesFullHearts:feature-transform-hook

Conversation

@ClearEyesFullHearts
Copy link

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant