jacksmith15 / statham-schema

Statham is a Python Model Parsing Library for JSON Schema.
https://statham-schema.readthedocs.io/en/latest/
MIT License
38 stars 11 forks source link

Support schemas with recursive references #63

Open jacksmith15 opened 4 years ago

jacksmith15 commented 4 years ago

There are several issues with this.

  1. The parser needs to be able to handle infinite schemas. This likely means instantiating default elements and keeping track of them, and then recursing through and setting attributes. There is a POC of this in feature/recursive-schema.
  2. The orderer needs to be able to identify cycles, and either annotate them for manual resolution in the output or resolve them as is.
  3. The DSL itself needs to be able to handle infinite recursion. This chiefly causes problems in places with default values. If the default value is the element with no arguments, but some properties have defaults, then instantiating with no arguments will trigger an infinite recursion.

What is the correct way to write recursive schemas in the DSL?

class TreeNode(Object):
    parent = Property(Element())

TreeNode.properties["value"].element = TreeNode

or maybe

class TreeNode(Object):
    parent = Property(lambda: TreeNode)
tanzimabsar commented 1 year ago

Any updates on this?