baml.json.schema
Lowers a BAML type to ordinary, provider-neutral JSON Schema.
Signature
Lowers a BAML type to ordinary, provider-neutral JSON Schema.
The type-level counterpart to the value conversions above: they move a
value between BAML and json, while this describes the shape a value
of t would take.
Optional fields are omitted from required, maps use schema-valued
additionalProperties, and unions use anyOf. Enums lower to a string
enum of their variant names, uint8array to string, and unknown to
the empty schema {}. A nullable type becomes a ["T", "null"] type list
where it can, and anyOf otherwise.
This pass does respect @alias and @skip, where the value conversions
do not — a schema is read by something outside BAML, so it must describe
the wire names. That is also why an enum variant lowers under its alias.
The root type is emitted inline, and every class and named alias beneath it
goes into $defs to be reached by $ref. That is what lets a recursive
graph terminate: a recursive root is emitted both inline and into $defs,
so the $ref back to itself resolves.
Throws
baml.errors.Unsupportedfor a type with no JSON Schema form, and for a class, enum, or alias the reflection context cannot resolve.
Source:<builtin>/baml/ns_json/json.bamlbytes 18654–18751