Does Yokai support nested schema validation? #57
-
Hi, I'm exploring the use of Yokai for validating configurations in my project, and I wanted to know whether Yokai supports nested schema validation. For example, if my config file includes a nested object like this: What I’ve tried: I looked at the examples, but most show flat structures. Tried writing a schema using dot notation, but it didn’t seem to validate nested objects properly. Any guidance or examples would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, Yokai does support nested validation, but not out of the box using dot notation like credentials.username. Instead, you can define nested validation by using object-based schema definitions. Here’s an example of how you might structure it: ts |
Beta Was this translation helpful? Give feedback.
Yes, Yokai does support nested validation, but not out of the box using dot notation like credentials.username.
Instead, you can define nested validation by using object-based schema definitions. Here’s an example of how you might structure it:
ts
Copy
const schema = {
database: {
host: { type: 'string' },
port: { type: 'number' },
credentials: {
username: { type: 'string' },
password: { type: 'string' }
}
}
};
If you're writing this schema in code, using the programmatic API is the most flexible. If you're writing it in YAML, try mirroring the structure.