Skip to content

Response validation is not executed for non-JSON responses #1079

@leeleahulkcs

Description

@leeleahulkcs

The latest release (as of right now [email protected]) does not validate the response if the response body does not contain JSON data (using res.send()) and res.json() is not explicitly called.

This is because the response validator hooks the res.json() call (https://github.com/cdimascio/express-openapi-validator/blob/v5.5.3/src/middlewares/openapi.response.validator.ts#L56, and https://github.com/cdimascio/express-openapi-validator/blob/v5.5.3/src/framework/modded.express.mung.ts#L59) in order to do call the validation code.

When the response is, for example, an image (or any other non-JSON data) - the res.json() is never called and the validation never occurs.

Thus, it is currently impossible to validate that the content-type and body of the response accurately matches what is defined in the response section of the OpenAPI document.

Would it be possible to hook the res.send() call instead, so that these types of responses can also be validated?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions