A utility package for ajv which provides additional keywords for usage within your schema.
This was created for a specific purpose and does not necessarily follow any schema specifications, but solely to meet my requirements. If you have any issues or suggestions, contributions are always welcome.
This package was created with guidance from ajv-keywords.
npm install @jaseeey/ajv-utils
or
yarn add @jaseeey/ajv-utils
const Ajv = require('ajv');
const ajv = new Ajv();
require('@jaseeey/ajv-utils')(ajv);
This keyword renames properties within an object to the desired name. It's primary use is to validate a payload received from an upstream system and transform the object property names as required in the local system.
The renameKeys
property in the schema is represented as an Object
where the key is the origin property name and the
value is the desired property name.
const schema = {
type: 'object',
properties: {
id: {
type: 'number'
},
name: {
type: 'string'
}
},
renameKeys: {
name: 'firstName'
}
};
const data = {
id: 123,
name: 'John'
};
ajv.compile(schema)(data);
// Result object:
// data = {
// id: 123,
// firstName: 'John'
// }