Refactor if-else blocks

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
pull/1801/head
Kévin Commaille 1 month ago
parent 52da075263
commit 7c5e123f4f
No known key found for this signature in database
GPG Key ID: 0C971D9DBC9D678D

@ -158,18 +158,16 @@
*/}} */}}
{{ define "partials/object-type-or-title" }} {{ define "partials/object-type-or-title" }}
{{ $type := "object" }} {{ $type := "object" }}
{{ if and .title (or .properties (not (or .additionalProperties .patternProperties))) }} {{ if .properties }}
{{/* {{/*
We only want to use the title in two cases: The object has its own (regular) properties, so we will make a
separate table for it. Refer to it using its title, if it has one.
* The object is rendered as a separate table that will use the same
title, which means that the object must have `properties`.
* The object doesn't define any properties, because showing the title
(like `EventFilter`) is better than showing `object`.
*/}} */}}
{{ $type = .title | htmlEscape }} {{ if .title }}
{{ if .anchor }} {{ $type = .title | htmlEscape }}
{{ $type = printf "<a href=\"#%s\">%s</a>" (htmlEscape .anchor) $type }} {{ if .anchor }}
{{ $type = printf "<a href=\"#%s\">%s</a>" (htmlEscape .anchor) $type }}
{{ end }}
{{ end }} {{ end }}
{{ else if reflect.IsMap .additionalProperties }} {{ else if reflect.IsMap .additionalProperties }}
{{/* {{/*
@ -192,6 +190,13 @@
{{ end }} {{ end }}
{{ $type = delimit (slice "{string: " (delimit $types "|") "}" ) "" }} {{ $type = delimit (slice "{string: " (delimit $types "|") "}" ) "" }}
{{ else if .title }}
{{/*
No properties, so there won't be a separate table. We use the title
anyway, because showing the title (like `EventFilter`) is better
than showing `object`.
*/}}
{{ $type = .title }}
{{ end }} {{ end }}
{{ return $type }} {{ return $type }}

Loading…
Cancel
Save