z-schema
z-schema copied to clipboard
API to get corresponding schema path for data and path
Let's say you have a JSON Schema document and an object being validated. What if I wanted to know what portion of the JSON Schema document corresponding to a particular path within the data being validated. For example:
JSON Schema
{
"type": "object",
"properties": {
"id": {
"type": "string"
}
}
}
Data
{
"id": "some-uuid"
}
How can I get from ["id"] (the path in the data object) to ["properties", "id"] (the path in the JSON Schema document)? This is a very simple example and would become more complex based on nested schemas, arrays, etc.
I'm not saying there has to be an API provided by z-schema, just wondering what you think about something like this.
Well, the errors should already point to place where the validation failed, so the API should be possible. You probably would need to propose an API, sample inputs/outputs and then we could see how the implementation could be done. It's been a while since I've worked on this so I don't remember the exacts.
Yes, for validation errors the path is there. I was just wondering about a more general API that isn't directly tied to validation.