understanding-json-schema icon indicating copy to clipboard operation
understanding-json-schema copied to clipboard

Example of biredirectional relationship

Open snimavat opened this issue 8 years ago • 2 comments

https://spacetelescope.github.io/understanding-json-schema/structuring.html Relations can be expressed using $ref and definitions. Can you put an example of how to handle bidirectional relationships such as below

class Person {
  Nose nose
}

Class Nose {
  Person person
}

When generating schema for person, we can have $ref and defintion for person.. but how should the person reference in nose should be handled.

Also, How many levels deep, Human > Head > Brain > Nerves etc

snimavat avatar Sep 01 '17 08:09 snimavat

Sorry for the delayed response. I'm taking this project out of the deep freeze :)

This seems like an infinitely looping relationship. Can you provide a JSON snippet of what you are trying to validate? It seems like at a minimum you'd need to make either Person.Nose or Nose.Person optional so the data structure would have an opportunity to "stop" recursing.

mdboom avatar Aug 22 '18 15:08 mdboom

Also, to note, the spec says you MUST NOT run $ref in a recursive loop in your schemas. https://tools.ietf.org/html/draft-handrews-json-schema-01#section-8.3

Relequestual avatar Aug 23 '18 15:08 Relequestual