Skip to content
This repository has been archived by the owner on Apr 15, 2022. It is now read-only.

Handle recursive types #2

Open
randomPoison opened this issue Feb 17, 2020 · 0 comments
Open

Handle recursive types #2

randomPoison opened this issue Feb 17, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@randomPoison
Copy link
Owner

The current setup has no way of gracefully handling recursive types; Recursively describing a type will expand the type tree forever with no way of stopping. In order to support recursive types we don't need to change anything about the Describe trait. Most of the work is handled by the Describer implementation:

  • A Describer should keep track of visited types and emit the appropriate type reference description.
  • When appropriate, a Describer should allow users to configure how type references in recursive types are handled, e.g. expanding the first occurrence of a type and then emitting a type ref for subsequent occurrences (ensuring that a generated schema is fully self-describing) vs always emitting type refs (which simplifies generated schemas but requires that all included types be described separately).

To update the provided Schema type and its describer, the following changes will also need to be made:

  • Add a TypeRef variant to the Schema containing a TypeName value`.
  • Internally track the TypeId of visited types and emits TypeRef for a named type after the first time its visited.
  • Support an alternate description mode where all named types are described as TypeRef.

It might be a good idea to provide a helper type that handles the common logic of tracking visited types. That logic is probably going to need to be shared by all Describer implementations, so we should provide utilities to reduce code duplication.

@randomPoison randomPoison added the enhancement New feature or request label Feb 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant