-
-
Notifications
You must be signed in to change notification settings - Fork 49
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 (trim) on nested objects via definitions is not working #152
Comments
you need to activate ajv-keywords with transform as a keyword |
Obviously, I did activated "transform" keyword. Without it I get: Here is full example (
And the output of the spec is as follows:
As you can see, Field |
Hi! I do have the same issue @Vitaljok is encoutering. "ajv": "^8.6.0",
"ajv-keywords": "^5.0.0",
"ajv-merge-patch": "^5.0.1" OriginI have a lot of big schema with nested element or $ref.
NoticeIt appears that all schema coming from a function disable Test: const Ajv = require('ajv');
const ajv = new Ajv({ coerceTypes: 'array', allowUnionTypes: true });
require('ajv-merge-patch')(ajv);
require("ajv-keywords")(ajv);
const create = {
type: 'object',
properties: {
body: {
type: 'object',
required: ['name'],
properties: {
name: {
type: 'string',
transform: ['trim']
}
}
}
}
};
const update = {
$merge: {
source: create,
with: {
properties: {
body: {
required: []
}
}
}
}
};
const createValidate = ajv.compile(create);
const updateValidate = ajv.compile(update);
const data = {
body: {
name: ' Test string to Trim '
}
};
function _(validate, data) {
try {
validate(data);
console.log({ data });
} catch (e) {
console.log({ e });
}
}
_(updateValidate, data);
_(createValidate, data); Output: updateCase = { data: { body: { name: ' Test string to Trim ' } } }
createCase = { data: { body: { name: 'Test string to Trim' } } } I can send the other methods I used, but ultimately, I am forced to paste my entire schema just to remove |
Hello!
I have found interesting behavior of transform keyword, which is probably a bug.
In short:
"transform": [ "trim" ]
is not working on nested objects if specified via definitions.The schema:
Input data:
Expected results: all strings are trimmed.
Actual results: string
b
in nested objects is not trimmedMy versions:
Thanks!
The text was updated successfully, but these errors were encountered: