Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transform keyword, is not working with 'toLowerCase' after updating to v3.4.0 #91

Closed
carlos-toscano opened this issue Feb 21, 2019 · 7 comments

Comments

@carlos-toscano
Copy link

Hi, I did the update to 3.4.0, and i´m using transform keyword, with 'toLowerCase', but this doesn´t do the transform.

Is needed to add a new keyword to keep this functionality?, thanks.

@epoberezkin
Copy link
Member

It's difficult to say what you do wrong without a code sample. If you follow docs and code in tests it will work.

@carlos-toscano
Copy link
Author

@epoberezkin , thanks for your answer, I discover that this problem is caused by updating the 'ajv' package, using version 6.9.0 or above, were there changes to add this kind of packages?

here an example

const Ajv = require('ajv');
const ajv = new Ajv({
  allErrors: true,
  removeAdditional: 'all',
  useDefaults: true,
  coerceTypes: true
});

require('ajv-keywords')(ajv, 'transform');

const schema = {
    "$schema": "http://json-schema.org/draft-07/schema",
    "title": "Transform Example",
    "description": "The transform keywork doesnt transform object",
    "type": "object",
    "properties": {
        "email": {
            "type": "string",
            "description": "User email",
            "minLength": 5,
            "transform": ["trim", "toLowerCase"]
        },
        "password": {
            "type": "string",
            "description": "User password",
            "minLength": 1
        }
    },
    "required": [
        "email",
        "password"
    ]
};

ajv.addSchema(schema, 'login')

const data = {
	email: "carloS ",
	password: "secret"
};

test(data);

console.log(data);

function test(data) {
  var valid = ajv.validate('login', data);
  if (valid) console.log('Valid!');
  else console.log(ajv.errors);
}

Regards

@epoberezkin
Copy link
Member

https://runkit.com/esp/5c6f2ba63c877f00138ea8e2

The culprit seems to be removeAdditional option, and it indeed starts to happen in 6.9.0

It can be related to ajv-validator/ajv#955

@epoberezkin
Copy link
Member

definitely Ajv issue fixing it there.

@carlos-toscano
Copy link
Author

@epoberezkin, oka, I understand, thank you for support.

@epoberezkin
Copy link
Member

fixed in ajv 6.9.2

@carlos-toscano
Copy link
Author

fixed in ajv 6.9.2

Nice, I confirm the fix, now it works fine!, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants