I’ve started looking into this problem, and approach I’m planning to use is:
is to parse the JSON schema into an AST that reflects the way JSONSchema is expressed
flatten the AST into a more restrictive AST (so that every sub-object can become its own record type, $ref’s can make sense, and complex magic like oneOf and allOf can carved out)
generate ReScript code directly from the flattened-AST
At no point would I be using one of the internal compiler ASTs - it’s too much trouble.
For similar projects I’ve created that both do code generation, I spit out the code directly and let the builtin formatter clean it up, as its much quicker and doesn’t require compiler internals (which I don’t have the time to familiarise myself with):