diff --git a/layouts/partials/json-schema/resolve-example.html b/layouts/partials/json-schema/resolve-example.html index 51ce6d53..90620b72 100644 --- a/layouts/partials/json-schema/resolve-example.html +++ b/layouts/partials/json-schema/resolve-example.html @@ -11,19 +11,37 @@ {{ $this_object := partial "json-schema/resolve-allof" . }} -{{ if eq $this_object.type "object" }} +{{ $example := $this_object.example }} - {{ if not $this_object.example }} - {{ $this_object := merge (dict "example" dict ) $this_object }} +{{ if eq $this_object.type "object" }} + {{ if not $example }} + {{ $example = dict }} {{ end }} {{ range $key, $property := $this_object.properties}} {{ $this_property_example := partial "json-schema/resolve-example" $property }} {{ if $this_property_example }} - {{ $this_object = merge (dict "example" (dict $key $this_property_example)) $this_object }} + {{ $example = merge (dict $key $this_property_example) $example }} + {{ end }} + {{ end }} + +{{ else if eq $this_object.type "array" }} + + {{ if not $example }} + {{/* 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 $this_object.example }} +{{ return $example }} diff --git a/layouts/partials/openapi/render-request.html b/layouts/partials/openapi/render-request.html index 1695c2f8..5e801299 100644 --- a/layouts/partials/openapi/render-request.html +++ b/layouts/partials/openapi/render-request.html @@ -47,19 +47,13 @@

Request body example

{{ $example := partial "json-schema/resolve-example" $schema }} - {{ if $example }} - {{ $example_json := jsonify (dict "indent" " ") $example }} - {{ $example_json = replace $example_json "\\u003c" "<" }} - {{ $example_json = replace $example_json "\\u003e" ">" | safeHTML }} + {{ $example_json := jsonify (dict "indent" " ") $example }} + {{ $example_json = replace $example_json "\\u003c" "<" }} + {{ $example_json = replace $example_json "\\u003e" ">" | safeHTML }} ```json {{ $example_json }} ``` - - {{ else }} - {{ partial "alert" (dict "type" "warning" "omit_title" "true" "color" "warning" "content" "Specification error: Example invalid or not present") }} - {{ end }} - {{ end }} {{ else }} diff --git a/layouts/partials/openapi/render-responses.html b/layouts/partials/openapi/render-responses.html index c92aba8e..350b0257 100644 --- a/layouts/partials/openapi/render-responses.html +++ b/layouts/partials/openapi/render-responses.html @@ -79,19 +79,13 @@ {{ $example = index $example "application/json" }} {{ end }} - {{ if $example }} - {{ $example_json := jsonify (dict "indent" " ") $example }} - {{ $example_json = replace $example_json "\\u003c" "<" }} - {{ $example_json = replace $example_json "\\u003e" ">" | safeHTML }} + {{ $example_json := jsonify (dict "indent" " ") $example }} + {{ $example_json = replace $example_json "\\u003c" "<" }} + {{ $example_json = replace $example_json "\\u003e" ">" | safeHTML }} ```json {{ $example_json }} ``` - - {{ else }} - {{ partial "alert" (dict "type" "warning" "omit_title" "true" "color" "warning" "content" "Specification error: Example invalid or not present") }} - {{ end }} - {{ end }} {{ end }} {{ end }}