Skip to content

nimgent/structured_output/jsonschema_derive

This page is generated from the module’s exported API and ## documentation comments.

Compile-time derivation of JSON Schema from Nim types.Optional field annotations understood by jsonSchema. They are declared as pragmas so they can be used directly on object fields without generating runtime code.

Add a JSON Schema description.

template jsonDescription(value: static[string]) {.pragma.}

Type parameters: value:type.

Name Type Default
value static[string]

View source

Set a numeric minimum.

template jsonMinimum(value: static[int]) {.pragma.}

Type parameters: value:type.

Name Type Default
value static[int]

View source

Set a numeric maximum.

template jsonMaximum(value: static[int]) {.pragma.}

Type parameters: value:type.

Name Type Default
value static[int]

View source

Set a string minimum length.

template jsonMinLength(value: static[int]) {.pragma.}

Type parameters: value:type.

Name Type Default
value static[int]

View source

Set a string maximum length.

template jsonMaxLength(value: static[int]) {.pragma.}

Type parameters: value:type.

Name Type Default
value static[int]

View source

Set an array minimum length.

template jsonMinItems(value: static[int]) {.pragma.}

Type parameters: value:type.

Name Type Default
value static[int]

View source

Set an array maximum length.

template jsonMaxItems(value: static[int]) {.pragma.}

Type parameters: value:type.

Name Type Default
value static[int]

View source

Set a string pattern.

template jsonPattern(value: static[string]) {.pragma.}

Type parameters: value:type.

Name Type Default
value static[string]

View source

Mark an object field as optional.

template jsonOptional() {.pragma.}

View source

OpenAI structured-output names: at most 64 [a-zA-Z0-9_-] characters.

proc schemaName(s: string): string {.raises: [], tags: [], forbids: [].}

Returns: string.

Name Type Default
s string

View source

JSON Schema for Nim objects, variants, containers, generics, enums, and primitives. Field pragmas add constraints or make a property optional. Option fields stay in required as [T, null] (OpenAI strict).

macro jsonSchema(T: typedesc): JsonNode

Type parameters: T:type.

Returns: JsonNode.

Name Type Default
T typedesc

View source