ajv-keywords icon indicating copy to clipboard operation
ajv-keywords copied to clipboard

transfom: ['trim'] becomes empty after compile

Open rucebee opened this issue 4 years ago • 2 comments

Not sure this is ajv-keywords bug or ajv itself, or even this is a bug of a feature)) But it was very tricky to find out why transform trim sometimes doesn't work

It turns that ajv.compile spoils my userSchema after first call and array items are vanished

"ajv": "^8.6.3", "ajv-keywords": "^5.0.0",

    console.log(JSON.stringify(userSchema))
//{"type":"object","properties":{"id":{"type":"string","allOf":[{"transform":["trim"] ...

    ajv.compile(userSchema)

    console.log(JSON.stringify(userSchema))
//{"type":"object","properties":{"id":{"type":"string","allOf":[{"transform":[]...

    const validate = ajv.compile(userSchema)

This is not expected behavior

rucebee avatar Sep 25 '21 10:09 rucebee

should I use deep clone for schemas to avoid this? or is there any better solution?

rucebee avatar Sep 25 '21 10:09 rucebee

I need to reproduce - looks like it’s a big, should be fixed

epoberezkin avatar Sep 25 '21 13:09 epoberezkin