Reputation: 1879
my fastify 3 (ajv6) use this settings:
ajv: {
customOptions: {
allErrors: true,
removeAdditional: true,
jsonPointers: true
},
plugins: [require('ajv-errors')],
},
as ajv 8 removed jsonpointers so i delete it.
but it still throw errors that in my project. the reproduce project is in this repo, please check. https://github.com/radiorz/fastify-lerna-ajv-error-demo
error message :
Error compiling schema, function code: const schema26 = scope.schema[20];const obj0 = scope.obj[0];return function validate24(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(data && typeof data == "object" && !Array.isArray(data)){if(data.parameters === undefined){const err0 = {instancePath,schemaPath:"#/required",keyword:"required",params:{missingProperty: "parameters"},message:"must have required property '"+"parameters"+"'"};if(vErrors === null){vErrors = [err0];}else {vErrors.push(err0);}errors++;}for(const key0 in data){if(!(key0 === "parameters")){delete data[key0];}}if(data.parameters !== undefined){let data0 = data.parameters;if(typeof data0 !== "string"){let dataType0 = typeof data0;let coerced0 = undefined;if(dataType0 == 'object' && Array.isArray(data0) && data0.length == 1){data0 = data0[0];dataType0 = typeof data0;if(typeof data0 === "string"){coerced0 = data0;}}if(!(coerced0 !== undefined)){if(dataType0 == "number" || dataType0 == "boolean"){coerced0 = "" + data0;}else if(data0 === null){coerced0 = "";}else {const err1 = {instancePath:instancePath+"/parameters",schemaPath:"#/properties/parameters/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err1];}else {vErrors.push(err1);}errors++;}}if(coerced0 !== undefined){data0 = coerced0;if(data !== undefined){data["parameters"] = coerced0;}}}}}else {const err2 = {instancePath,schemaPath:"#/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err2];}else {vErrors.push(err2);}errors++;}if(errors > 0){const emErrors0 = {"required":{"parameters":[]}};let emParamsErrors0;for(const err3 of vErrors){if(((((({"str":"err3"}.keyword !== "errorMessage") && (!{"str":"err3"}.emUsed)) && ({"str":"err3"}.instancePath === instancePath)) && ({"str":"err3"}.keyword in {"str":"emErrors0"})) && ({"str":"err3"}.schemaPath.indexOf("#") === 0)) && (/^/[^/]*$/.test({"str":"err3"}.schemaPath.slice(1)))){emParamsErrors0 = {"str":"emErrors0"}[{"str":"err3"}.keyword][{"str":"err3"}.params[{"str":"emPropParams0"}]];if(emParamsErrors0){{"str":"emParamsErrors0"}.push({"str":"err3"});{"str":"err3"}.emUsed = true;}}}for(const key1 in emErro
Upvotes: 2
Views: 515
Reputation: 1
having the same error - any solutions?
"fastify": "4.1.0" "ajv-errors": "^3.0.0"
ajv: {
customOptions: {
allErrors: true,
},
plugins: [AjvErrors],
},
Error: Cannot find module 'ajv'
EDIT: looks like reinstalling node modules fixed this issue - if you're using fasify 4 or above you can use ajv-errors 3 if you're using below fastify version 4 you have to use ajv-errors 1
Upvotes: 0