@verii/fastify-plugins 1.4.0-pre.1794466052.0 → 1.4.0-pre.1794469820.0

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@verii/fastify-plugins",
3
- "version": "1.4.0-pre.1794466052.0",
3
+ "version": "1.4.0-pre.1794469820.0",
4
4
  "description": "Plugin for handling errors",
5
5
  "repository": "https://github.com/LFDT-Verii/core",
6
6
  "main": "index.js",
@@ -17,9 +17,9 @@
17
17
  "quick-lru": "~7.3.0",
18
18
  "statuses": "~2.0.2",
19
19
  "toidentifier": "~1.0.1",
20
- "@verii/crypto": "1.4.0-pre.1794466052.0",
21
- "@verii/error-aggregation": "1.4.0-pre.1794466052.0",
22
- "@verii/http-client": "1.4.0-pre.1794466052.0"
20
+ "@verii/crypto": "1.4.0-pre.1794469820.0",
21
+ "@verii/http-client": "1.4.0-pre.1794469820.0",
22
+ "@verii/error-aggregation": "1.4.0-pre.1794469820.0"
23
23
  },
24
24
  "devDependencies": {
25
25
  "eslint": "9.39.5",
@@ -83,7 +83,7 @@ const autoSchemaPlugin = async (fastify, opts) => {
83
83
  const buildResponse = (schema) => {
84
84
  const response = { ...schema.response, '5xx': errorSchemaRef };
85
85
  if (schema.body != null || schema.query != null) {
86
- response[options.validationErrorCode] = errorSchemaRef;
86
+ response[options.validationErrorCode] = validationErrorResponse(schema);
87
87
  }
88
88
  if (schema.params != null) {
89
89
  response[404] = errorSchemaRef;
@@ -95,6 +95,11 @@ const autoSchemaPlugin = async (fastify, opts) => {
95
95
 
96
96
  return response;
97
97
  };
98
+
99
+ // A route can declare its own validation error response, for example one
100
+ // that adds fields to the error schema. Otherwise it gets the error schema.
101
+ const validationErrorResponse = (schema) =>
102
+ schema.response?.[options.validationErrorCode] ?? errorSchemaRef;
98
103
  };
99
104
 
100
105
  module.exports = { autoSchemaPlugin: fp(autoSchemaPlugin) };