fix: warn on incompatible response - #1035
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a response-validation error hook to the Express OpenAPI validator setup so the service logs a warning when outgoing responses don’t match the OpenAPI schema (“incompatible response”).
Changes:
- Introduces
validateResponseErrormiddleware helper to warn on response validation failures. - Wires
validateResponseErrorintoOpenApiValidator.middleware({ validateResponses: { onError } }).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/middleware/error.ts | Adds a response-validation onError handler that logs a warning. |
| src/app.ts | Registers the new onError handler under validateResponses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/middleware/error.ts:13
- Avoid importing
InternalServerErrorfrom the package’s internaldist/...path and typing the callback error that narrowly. Internal subpath imports can break with package export maps / version changes, and a too-specific parameter type can make theonErrorcallback fail TypeScript assignment if the library passes a different error shape. Prefer a stable/public type (orunknown) and drop the deep import; also consider logging URL for easier diagnostics.
import { debug, error, warn } from 'console'
import { Request, Response } from 'express'
import { InternalServerError } from 'express-openapi-validator/dist/openapi.validator'
import { HttpError, OtomiError } from 'src/error'
import { OpenApiRequest } from 'src/otomi-models'
import { cleanEnv } from 'src/validators'
import { cleanSession } from './session'
const env = cleanEnv({})
export function validateResponseError(err: InternalServerError, body: any, req: Request): void {
warn(`Response body fails validation: `, err, req.method)
return
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/middleware/error.ts:13
validateResponseErrorhas a redundantreturn, usesanytypes (loses type-safety), and the warning log only includes the HTTP method (no URL/path), which makes it hard to identify which endpoint produced the invalid response. Consider typing inputs asunknown, removing the redundantreturn, and includingreq.originalUrl(orreq.path) in the log output.
export function validateResponseError(err: any, _body: any, req: Request): void {
warn(`Response body fails validation: `, err, req.method)
return
j-zimnowoda
enabled auto-merge (squash)
July 23, 2026 09:27
dennisvankekem
approved these changes
Jul 23, 2026
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.
This pull request introduces improved error handling for response validation in the application. The main change is the addition of a custom handler for response validation errors, which logs warnings when a response does not conform to the defined schema, instead of returning HTTP 500 error.
Warning example: