You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've created this test (using the code from object.spec.ts) and using a simple schema with some nested property.
The idea, based on the documentation, is that the error message for the "required" keyword should be replaced, but this it's not happening.
describe("errorMessage value is an object custom",()=>{constajv=_ajv();it("should replace keyword errors with custom error messages",()=>{constschema: SchemaObject={type: "object",required: ["foo","sections"],properties: {foo: {type: "integer"},sections: {minItems: 1,type: "array",items: {type: "object",properties: {identityFieldValue: {type: "string",minLength: 1},},required: ["identityFieldValue"],}}},additionalProperties: false,errorMessage: {type: "should be an object",required: "should have property foo",additionalProperties: "should not have properties other than foo",},};constvalidate=ajv.compile(schema);testInvalid({foo: 1,sections: [{}]},[["required"]]);functiontestInvalid(data: any,expectedErrors: (string|string[])[]): void{assert.strictEqual(validate(data),false)assert.strictEqual(validate.errors?.length,expectedErrors.length)validate.errors.forEach((err,i)=>{constexpectedErr=expectedErrors[i]if(Array.isArray(expectedErr)){// errorMessage errorassert.strictEqual(err.keyword,"errorMessage")assert.strictEqual(err.message,schema.errorMessage[err.params.errors[0].keyword])assert.strictEqual(err.instancePath,"")assert.strictEqual(err.schemaPath,"#/errorMessage")constreplacedKeywords=err.params.errors.map((e: ErrorObject)=>e.keyword)assert.deepStrictEqual(Array.from(replacedKeywords.sort()),Array.from(expectedErr.sort()))}else{// original errorassert.strictEqual(err.keyword,expectedErr)}})}})});
The text was updated successfully, but these errors were encountered:
ajv-errors:3.0.0
I've created this test (using the code from object.spec.ts) and using a simple schema with some nested property.
The idea, based on the documentation, is that the error message for the "required" keyword should be replaced, but this it's not happening.
The error object is generated like this:
This is the test to replicate the problem:
The text was updated successfully, but these errors were encountered: