Generate a JSON Schema (2020-12) fragment describing the D type T.
The mapping is complete and fully recursive — every type expressible as a
tool parameter or structured result maps to a faithful schema. Mapping:
- bool -> {type: "boolean"}
- integral -> {type: "integer"}
- floating point -> {type: "number"}
- string -> {type: "string"}
- enum -> {type: "string", enum: [members…]}
- arrays/slices -> {type: "array", items: <recursive>}
- associative arrays (string keys) ->
{type: "object", additionalProperties: <recursive>}
- struct -> `{type: "object", properties: <recursive>,
required: <fields that are neither Nullable!T nor have a default>}`
- Nullable!T -> {anyOf: [schema(T), {type: "null"}]} (accepts both the
inner type and JSON null; optionality is handled by the enclosing object
via required)
- SumType!(A, B, …) / tagged unions -> {anyOf: [schema(A), schema(B), …]}
- std.datetime types: SysTime/DateTime -> {type: "string", format: "date-time"};
Date -> {type: "string", format: "date"};
TimeOfDay -> {type: "string", format: "time"}
Any other type — pointers, delegates, classes, void, or an associative
array with a non-string key — is genuinely unmappable and raises a clear
static assert(false, …) at compile time. There is never a {type:"string"}
fallback for a structured type.
Generate a JSON Schema (2020-12) fragment describing the D type T.
The mapping is complete and fully recursive — every type expressible as a tool parameter or structured result maps to a faithful schema. Mapping:
- bool -> {type: "boolean"} - integral -> {type: "integer"} - floating point -> {type: "number"} - string -> {type: "string"} - enum -> {type: "string", enum: [members…]} - arrays/slices -> {type: "array", items: <recursive>} - associative arrays (string keys) -> {type: "object", additionalProperties: <recursive>} - struct -> `{type: "object", properties: <recursive>, required: <fields that are neither Nullable!T nor have a default>}` - Nullable!T -> {anyOf: [schema(T), {type: "null"}]} (accepts both the inner type and JSON null; optionality is handled by the enclosing object via required) - SumType!(A, B, …) / tagged unions -> {anyOf: [schema(A), schema(B), …]} - std.datetime types: SysTime/DateTime -> {type: "string", format: "date-time"}; Date -> {type: "string", format: "date"}; TimeOfDay -> {type: "string", format: "time"}
Any other type — pointers, delegates, classes, void, or an associative array with a non-string key — is genuinely unmappable and raises a clear static assert(false, …) at compile time. There is never a {type:"string"} fallback for a structured type.