@trojs/openapi-server 1.11.1 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trojs/openapi-server",
3
3
  "description": "OpenAPI Server",
4
- "version": "1.11.1",
4
+ "version": "1.12.1",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
@@ -76,4 +76,4 @@
76
76
  "send@<=0.19.0": "^0.19.0",
77
77
  "cookie@<=0.7.0": "0.7.0"
78
78
  }
79
- }
79
+ }
@@ -1,4 +1,4 @@
1
- export const responseValidation = (context, request, response) => {
1
+ export default (logger) => (context, request, response) => {
2
2
  const responseDoesntNeedValidation = response.statusCode >= 400
3
3
  if (responseDoesntNeedValidation) {
4
4
  return response.json(context.response)
@@ -9,6 +9,15 @@ export const responseValidation = (context, request, response) => {
9
9
  context.operation
10
10
  )
11
11
  if (valid?.errors) {
12
+ if (logger) {
13
+ logger.error({
14
+ message: 'Response validation failed',
15
+ errors: valid.errors,
16
+ operation: context.operation,
17
+ statusCode: response.statusCode,
18
+ response: context.response
19
+ })
20
+ }
12
21
  return response.status(502).json({
13
22
  errors: valid.errors,
14
23
  status: 502,
package/src/router.js CHANGED
@@ -4,7 +4,7 @@ import { makeExpressCallback } from './express-callback.js'
4
4
  import { operationIds } from './operation-ids.js'
5
5
  import { notFound } from './handlers/not-found.js'
6
6
  import { requestValidation } from './handlers/request-validation.js'
7
- import { responseValidation } from './handlers/response-validation.js'
7
+ import makeResponseValidation from './handlers/response-validation.js'
8
8
  import { unauthorized } from './handlers/unauthorized.js'
9
9
 
10
10
  /**
@@ -66,7 +66,7 @@ export const setupRouter = ({
66
66
  unauthorizedHandler: unauthorizedHandler || unauthorized,
67
67
  validationFail: requestValidation,
68
68
  notFound,
69
- postResponseHandler: responseValidation
69
+ postResponseHandler: makeResponseValidation(logger)
70
70
  })
71
71
 
72
72
  operationIds({ specification: openAPISpecification }).forEach(