Hof Schemas are CUE values and serve as the contract between you, the generator writer, and your users. Your schemas capture the essence of the problem or application. They provide the constraints for users developing with your generator and ensure input to your generator is valid.
A Schema in Hof
A Hof Schema is a CUE value.
A Minimal REST Schema
Let’s start by sketching out the minimal definition for a server.
We put this in the
schema/ directory and thus CUE package.
Routes and Handlers
Routes are a main focal point of REST servers. When we generate the code, we will need handlers for each. Here is the schema for a Route that will have a handler generated.
These are features you may want to provide to your server users. While the user only has to set a boolean or flag, they can get advanced capabilities which are the consistent for every generated server.
These are fields and values you can infer from a user’s input that they do not need to set. They are often for making template writing easier by formatting or collecting values. You can also transform or enrich user input using CUE here as well as in generators. Later, we will use this technique to define the CRUD routes for a resource based on the user’s data model.
Language and Tool Fields
There are typically language or tools specifics which may need to be configured. Often, you will want to make some of these accessible to your users. You can even create generators which are multilingual or lets your user select their preferred technologies.
This is our final schema after combining all the parts above.