Access root data in code generation custom keyword
See original GitHub issueWhat version of Ajv you are you using? 7.2.3
What problem do you want to solve? I’m trying to validate whether array items are used as object keys.
Let’s say I have a schema like this
{
"keys": {
"type": "array",
"arrayItemsAreKeysOf": "/specialObject" // attempting to implement this custom keyword
},
"specialObject": {
"type": "object"
}
}
This is valid:
{
"keys": ["one", "two"],
"specialObject": {
"one": true,
"two": true
}
}
This is invalid:
{
"keys": ["one", "two", "three"],
"specialObject": {
"one": true,
"two": true
}
}
What do you think is the correct solution to problem? In ajv v6 I had a custom “validate” function to check this:
ajv.addKeyword('arrayItemsAreKeysOf', {
validate(schema, data, parentSchema, dataPath, parentData, propertyName, rootData) {
const validArrayItems = R.pipe(
R.path(schema.split('/')),
R.keys,
)(rootData);
return R.all(R.includes(R.__, validArrayItems))(data);
},
errors: false,
});
(If you’re unfamiliar with Ramda, this takes the keys of a given path (/specialObject
) from rootData
and then checks if all items of data
(keys
array in examples) are present)
And it worked fine. I tried rewriting this for ajv v7+ using the code generation keyword, but I’m not sure if it’s possible to access rootData
there.
Will you be able to implement it? Maybe it’s already possible to do what I’m trying to achieve?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Embedded Coder Dictionary - MathWorks
On the C Code tab, select Code Interface > Embedded Coder Dictionary. The Embedded Coder Dictionary window displays code generation definitions that are...
Read more >ROOTUsersGuide - CERN
ROOT is an object-oriented framework aimed at solving the data analysis challenges of high-energy physics. There are two key words in this definition, ......
Read more >I/O of custom classes - ROOT
I/O of custom classes. On this page. Generating dictionaries. Using ACLiC; Using rootcling. Embedding the rootcling call into a GNU Makefile. Using CMake....
Read more >Generate code | IntelliJ IDEA Documentation - JetBrains
IntelliJ IDEA provides multiple ways to generate common code constructs and recurring elements, which helps you increase productivity.
Read more >Embedded Coder™ User's Guide - Purdue Engineering
Pointers for Signals and Parameters Using Simulink Data. Objects . ... Generating Code with Custom Storage Classes . ... Referenced by: '<Root>/Constant'.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have rewritten the above v6 code to v7, took
rootData
fromdataCtx
:So
rootData
is only accessible in validation functions and not in code generation functions, right?To make it slightly more clear for anyone stumbling on this, this is how you access the rootData in the
code
function: