Guide
Schema and code
Check templates and data against a JSON Schema before each render, and write the first template straight from your classes.
On this page
The schema file
A template can have a JSON Schema next to it, with the same name:
rechnung.md
rechnung.schema.jsonWhen the file exists, every brevier render checks two things before it
prints:
- Each
{{ }}tag in the template names a field that the schema has. - The data matches the schema: required fields, types, lists.
If one check fails, nothing is printed. brevier lists every problem, with the template line for the first check.
When there is no schema file, brevier skips both checks.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"rechnung": {
"type": "object",
"properties": {
"nummer": { "type": "string", "title": "Rechnungsnummer" },
"summe": { "type": "number", "format": "decimal" }
},
"required": ["nummer", "summe"]
}
},
"required": ["rechnung"]
}A column's title in the schema is also the default header text of a
table block.
From your classes
You do not have to write the schema by hand. from-code reads your classes
and writes four files:
brevier from-code com.ww.Rechnung com.ww.Kunde --format md| File | Content |
|---|---|
rechnung.schema.json |
The schema, with one data root per class. |
rechnung.md |
A first template that uses every field. |
rechnung.css |
A stylesheet to start from. |
sample.json |
Sample data that matches the schema. |
The files take the name of the first class. --format html (the default)
writes an HTML template instead of Markdown.
| Classes | Written as | Needs |
|---|---|---|
| Java | com.ww.Rechnung |
Java 17 or newer. Set --classpath to your compiled classes. |
| Python | billing.models:Rechnung |
pydantic models or dataclasses, importable from the current folder. |
from-code never overwrites a file. If one of the four files exists, it
writes none of them. Add --force to replace them all.
