codecombat/treema

Create utility function for determining child working schemas

Closed this issue · 0 comments

When Treema creates the child of a node, it needs to determine the working schema of that child. Working schemas are denormalized versions of a JSON-schema where the combinatorial schema definitions (anyOf, allOf, oneOf) and references are respectively flattened and dereferenced into a series of simpler schemas Treema can choose from and build based off. See buildWorkingSchemas for how it does this. Most of the time, the working schema is just the schema in the properties array for the given key, or the schema of the items property, but there are these more complicated cases.

Currently the system determines working schemas in the static function make, but choosing working schemas would be useful on its own. Pull out a utility function that, given a parent schema, a tv4 instance (needed for dereferencing) and a key (or index), returns an array of working schemas. This will allow any system to walk through json data and determine, for each property, the working schemas for that property and, through tv4 validation of the extant value, figure out on its own which working schema to use.