Now
Given a schema with properties with no-escape symbols
When validate function is called with instance
Then the escape strategy adds decode/encode calls
Then the unnecessary calls are made during the runtime
tpl(if (${tpl.data}.hasOwnProperty(decodeURIComponent("${encodeURIComponent(propertyKey)}"))) {);
Should be
Given a schema with properties with no-escape symbols
When validate function is called with instance
Then the escape strategy doesn't add decode/encode calls
Then the unnecessary calls are not made during the runtime
Example
// schema
const jsonSchema = {
common: {
properties: {
type: {
enum: ['common']
}
},
required: [
'type'
]
}
};
// test
it('should return undefined if object is valid', () => {
const env = djv();
env.addSchema('test', jsonSchema);
const commonObj = {
type: 'common'
};
const errors = env.validate('test#/common', commonObj);
assert.equal(errors, undefined);
});
// generated function
if (data !== null && typeof data === 'object' && !Array.isArray(data)) {
if (!data.hasOwnProperty(decodeURIComponent("type"))) return {
keyword: 'required',
dataPath: decodeURIComponent(""),
schemaPath: decodeURIComponent("#/required")
};
}
if (data[decodeURIComponent('type')] != decodeURIComponent('common')) return {
keyword: 'enum',
dataPath: decodeURIComponent("'type'"),
schemaPath: decodeURIComponent("#'type'/enum")
};
}
Now
Should be
Example