z-schema icon indicating copy to clipboard operation
z-schema copied to clipboard

API to get corresponding schema path for data and path

Open whitlockjc opened this issue 7 years ago • 2 comments
trafficstars

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.

whitlockjc avatar Dec 04 '17 20:12 whitlockjc

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.

zaggino avatar Dec 06 '17 09:12 zaggino

Yes, for validation errors the path is there. I was just wondering about a more general API that isn't directly tied to validation.

whitlockjc avatar Dec 06 '17 17:12 whitlockjc