schema is the core data structure that you need to understand to become a Synth wizard. Schemas are JSON files
that encode the shape of the data you want to generate. All schemas are composed of
generators that are assembled by
the user to create complex data structures.
It's a little involved, so let's start with a simpler example: JSON!
If you've never actually seen how JSON is implemented under the hood, you may find this interesting.
One of the reasons for JSON's popularity is just how simple of a data structure it is. JSON is a recursive data
structure (just a tree but let's pretend we're smart) and can be defined in 8 lines of code (if you're wondering, this
So every node in a JSON tree, is one of 6 variants. Recursion occurs where
Objects can have children
which are also one of 6 variants.
We've based the Synth schema on the same design. But, what does this look like when you need to capture far more complexity than the JSON schema?
Much like the
Value node in a JSON tree, the
Schema nodes in the synth Schema give us the recursive data structure
which Synth can use to generate data.
Each of these
Schema variants, cover a bunch of different types of
Schema nodes, just to give an example,
StringSchema variant looks like this under the hood:
String types can be generated from regular expressions, date time generators and so on. For a comprehensive list
see the String docs.
Schema nodes have different fields depending on the type of node. This makes sense, if you are generating Id's,
you're going to want to specify different parameters to if you are generating a date or a time.
Schema nodes follow a similar template.
- There is a boolean
optionalfield, which tells Synth if a field is nullable or not.
- Next there is a
typefield, which specifies which top-level
Schematype the node is (
booletc.). Fields can often have a
subtypewhich disambiguates certain types (for example is a
f64or an unsigned integer
Schemanodes can have 0 or more fields which are specific to that node type. For more information refer to the documentation for that type.
In our example schema we have a namespace
my_app which has 2 collections -
Below is a tree representation of the schema Schema tree:
The corresponding namespace can be broken into 2 collections. The first,
And the second, the
The generators reference in this documentation is the best place to become familiar with all the different variants of schema nodes. This will let you write schemas for any of the data you might need.