{{/* Hugo-Native Schema Renderer Renders a JSON schema as a property table with nested object support. Similar to docusaurus-openapi's schema tables. Params: - schema: OpenAPI schema object - spec: The full OpenAPI spec object for resolving $ref - level: Nesting level (0 = root) */}} {{ $schema := .schema }} {{ $spec := .spec }} {{ $level := .level | default 0 }} {{ $type := $schema.type | default "object" }} {{ $properties := $schema.properties | default dict }} {{ $required := $schema.required | default slice }} {{ $example := $schema.example }} {{/* Convert required slice to map for easy lookup */}} {{ $requiredMap := dict }} {{ range $required }} {{ $requiredMap = merge $requiredMap (dict . true) }} {{ end }}
{{ if gt (len $properties) 0 }}
{{ range $propName, $propSchema := $properties }} {{ $isRequired := index $requiredMap $propName | default false }} {{ $propType := $propSchema.type | default "string" }} {{ $propDescription := $propSchema.description | default "" }} {{ $propFormat := $propSchema.format | default "" }} {{ $propEnum := $propSchema.enum | default slice }} {{ $propDefault := $propSchema.default }} {{ $propExample := $propSchema.example }} {{/* Build type display */}} {{ $typeDisplay := $propType }} {{ if eq $propType "array" }} {{ $itemsType := "object" }} {{ with $propSchema.items }} {{ $itemsType = .type | default "object" }} {{ end }} {{ $typeDisplay = printf "%s[]" $itemsType }} {{ else if $propFormat }} {{ $typeDisplay = printf "%s <%s>" $propType $propFormat }} {{ end }}
{{ $propName }} {{ if $isRequired }} required {{ end }} {{ $typeDisplay }}
{{ if $propDescription }}
{{ $propDescription | markdownify }}
{{ end }} {{/* Enum values */}} {{ if gt (len $propEnum) 0 }}
Allowed: {{ range $i, $val := $propEnum }} {{ if $i }}, {{ end }}{{ $val }} {{ end }}
{{ end }} {{/* Default value */}} {{ if $propDefault }}
Default: {{ $propDefault }}
{{ end }} {{/* Example value */}} {{ if $propExample }}
Example: {{ jsonify $propExample }}
{{ end }} {{/* Nested object/array rendering (limit depth to prevent infinite loops) */}} {{ if and (eq $propType "object") (lt $level 2) }} {{ with $propSchema.properties }} {{ partial "api/schema.html" (dict "schema" $propSchema "spec" $spec "level" (add $level 1)) }} {{ end }} {{ else if and (eq $propType "array") (lt $level 2) }} {{ with $propSchema.items }} {{ if isset . "properties" }} {{ partial "api/schema.html" (dict "schema" . "spec" $spec "level" (add $level 1)) }} {{ end }} {{ end }} {{ end }}
{{ end }}
{{ end }} {{/* Show example at schema level */}} {{ if and $example (eq $level 0) }}
Example request body
{{ jsonify (dict "indent" "  ") $example }}
{{ end }}