Open twifty opened 6 years ago
How would you see that being configured?
Just thinking out loud, but you could treat the keys as a regex. Something like:
const options = {
structure: {
school: {
'description?': 'string', //Optional, won't show in invalid array
code: 'number',
principal: {
name: 'string'
},
teachers: {
'/[\w-_]+/': {
name: 'string',
subject: 'string',
salary: 'number',
}
}
}
}
};
Checking the first and last char for the delimiter should keep things backwards compatible.
That could work, using all keys as regular expressions.
Want to make a PR out of this?
I'd be willing to build a PR for this, but I think a sanity rule is needed:
-When validating objects, non-RE keys are checked before RE keys
The issue is that we could get something like:
{
specificKey: 'string',
"/[A-Za-z_][A-Za-z0-9_]+/": { ... something else ... }
}
Note also that "/blah/" is actually a valid JSON key that would now need to be matched using a regexp. I don't see that as a problem, but it's definitely something to call out in the documentation.
I was so hoping this would fit into my project, but I can't see, either in your readme or tests, if it supports a prototype schema.
Given the following yaml:
Each
service
must conform to the same schema, but it's unknown how many there are or what keys they will use.Looking at the sources, I don't believe it is possible to read the file myself and apply a schema against an existing object. If it were, I could have done a multi stage validation.