keleshev / schema

Schema validation just got Pythonic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: How to define self referential schemas

alisaifee opened this issue · comments

I have a schema that references itself in a property, and couldn't figure out a way to declare this.

For example:

person = Schema({
   "first_name": str, 
   "last_name": str,
   "age": int,
   "children": [person]
}, name="person")
commented

hey, we did self-referential schemas this way:

person_defn = dict()
person_defn.update(
    {
        "first_name": str, 
        "last_name": str,
        "age": int,
        "children": [person_defn]
    }
)
person = Schema(person_defn)