{{/* For complex objects, example content is sometimes attached to the object's individual properties (and subproperties...), so to get a complete example for the whole object we need to iterate through its properties (and subproperties...) and assemble them. That's what this template does. */}} {{ $this_object := . }} {{ $example := $this_object.example }} {{ if not $example }} {{ if eq $this_object.type "object" }} {{ $example = dict }} {{ range $key, $property := $this_object.properties}} {{ $this_property_example := partial "json-schema/resolve-example" $property }} {{ if $this_property_example }} {{ $example = merge (dict $key $this_property_example) $example }} {{ end }} {{ end }} {{ else if eq $this_object.type "array" }} {{/* the "items" within an array can either be an object (where we have a list of items which match the schema), or a list (for tuple validation, where each item has a different schema). TODO: support tuple validation here. */}} {{ if reflect.IsMap $this_object.items }} {{ $items_example := partial "json-schema/resolve-example" $this_object.items }} {{ $example = slice $items_example }} {{ else }} {{ $example = slice }} {{ end }} {{ end }} {{ end }} {{ return $example }}