If an object definition already has an example, we shouldn't try to extend that definition by adding examples derived from the individual properties. Doing so is confusing, and there is no way to inhibit it when it is not desired. It's also not what the RapiDoc viewere does, so we end up with examples being inconsistent.
46 lines
1.4 KiB
HTML
46 lines
1.4 KiB
HTML
{{/*
|
|
|
|
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 := partial "json-schema/resolve-allof" . }}
|
|
|
|
{{ $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 }}
|