{#- Recursive JSON Schema renderer, styled for Tailwind Typography `prose`. Usage: {% from "partials/api-schema.njk" import schema %} {{ schema(node, apiSpec.schemas) }} `$ref` nodes are rendered as links to /developers/api/reference/schemas/ and never expanded inline, so recursion always terminates. -#} {% macro schema(node, schemas, depth) %} {%- if not node -%}

Not documented.

{%- elif node["$ref"] -%} {%- set name = node["$ref"] | apiRefName -%} {%- if schemas[name] -%}

Object {{ name }}.

{%- else -%}

Object {{ name }}.

{%- endif -%} {%- elif node.properties -%}
{%- for key, prop in node.properties -%} {%- set isArray = prop.type == "array" and prop["items"] -%} {%- set ref = prop["$ref"] or (isArray and prop["items"]["$ref"]) -%} {%- set refName = ref | apiRefName -%} {%- set nested = prop.properties or (isArray and prop["items"].properties) -%} {%- endfor -%}
FieldTypeRequiredDescription
{{ key }} {%- if refName and schemas[refName] -%} {{ prop | apiType }} {%- else -%} {{ prop | apiType }} {%- endif -%} {{ "yes" if key in (node.required or []) }} {{- prop.description -}} {%- if nested and not refName -%}
fields {{ schema(prop["items"] if isArray else prop, schemas, (depth or 0) + 1) }}
{%- endif -%}
{%- elif node.type == "array" -%}

Array of:

{{ schema(node["items"], schemas, (depth or 0) + 1) }} {%- else -%}

{{ node | apiType }}{% if node.description %} - {{ node.description }}{% endif %}

{%- endif -%} {% endmacro %}