Generating Dhall binding from json schemas

Hello,

I gave this topic a try to create a dhall-prometheus configuration schema using a simple schemastore-to-dhall.py script.

That seems like a viable solution to create quick bindings, at least it almost works with the prometheus schemas from SchemaStore . Is there other similar work to generate dhall package?

Cheers,
-Tristan

3 Likes

@tristanC: I like this! This is a really clever idea

I’m not aware of any other existing work along these lines

Nice, then I’m looking forward the hackage like documentation for dhall as we could also extract the attribute description from the json schemas.

Note that I investigated a couple more procedures to generate schemas:

  • Using dhall-kubernetes-generator to process the OpenShift openapi swagger file: dhall-openshift. That worked out of the box.
  • Parsing golang struct to create Tekton CRD binding: dhall-tekton. That is still very hacky as I don’t know golang, but given enough workaround, parsing the struct directly from the source code may be viable too. Before doing that, I tried using the dhall-kubernetes-generator --crd toggle, but that didn’t worked and the openAPIV3Schema got removed anyway, see this commit.

I think one of the issues with parsing go structs is that go has no real support for Optional or union types. So you’d either have to make everything Optional or use some sort of tagging scheme to add extra metadata.

For what it’s worth, i looked for omitempty in the json: annotation to detect Optional.