jsonschema.generate

Compile-time D-type → JSON Schema generator.

jsonSchemaOf!T derives a JSON Schema 2020-12 document (as a JsonNode) from a D type. The mapping is complete and fully recursive:

- bool{type: "boolean"} - integral → {type: "integer"} (unsigned types additionally get minimum: 0) - floating point → {type: "number"} - string{type: "string"} - enum{type: "string", enum: [members…]} - arrays/slices → {type: "array", items: …} - string-keyed associative arrays → {type: "object", additionalProperties: …} - struct{type: "object", properties: …, required: […]} - Nullable!T{anyOf: [schema(T), {type: "null"}]} - SumType!(A, B, …){anyOf: [schema(A), schema(B), …]} - std.datetime: SysTime/DateTime → string + format "date-time", Date → "date", TimeOfDay → "time"

Struct types that are referenced from more than one place, or recursively, are emitted once into $defs and referenced via $ref; everything else is inlined. Any other type (pointers, classes, delegates, non-string AA keys) is rejected with a clear static assert.

Render the result with toStdJson (std.json), nodeToVibeJson (jsonschema:vibe), or .toString — or compile it directly with compileSchema to validate instances against it.

Members

Functions

applyUdaFacets
void applyUdaFacets(JsonNode prop)

Fold the constraint-facet UDAs from a compile-time sequence (e.g. __traits(getAttributes, someSymbol)) onto an existing schema node: @minimum, @maximum, @pattern, @minLength, @maxLength, @minItems, @maxItems, @format, @title, and @schemaDefault map to the matching keyword; any other UDA is ignored.

jsonSchemaOf
JsonNode jsonSchemaOf()

Generate the JSON Schema for T with compile-time-known settings.

jsonSchemaOf
JsonNode jsonSchemaOf(GeneratorSettings settings)

Generate the JSON Schema for T.

Structs

GeneratorSettings
struct GeneratorSettings

Generation options.