From 7c5e123f4fa30da2eee1563aa6a23beecfd82611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Tue, 30 Apr 2024 18:08:27 +0200 Subject: [PATCH] Refactor if-else blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- .../partials/openapi/render-object-table.html | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/layouts/partials/openapi/render-object-table.html b/layouts/partials/openapi/render-object-table.html index 17bed313..179f6ab9 100644 --- a/layouts/partials/openapi/render-object-table.html +++ b/layouts/partials/openapi/render-object-table.html @@ -158,18 +158,16 @@ */}} {{ define "partials/object-type-or-title" }} {{ $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 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`. + 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. */}} - {{ $type = .title | htmlEscape }} - {{ if .anchor }} - {{ $type = printf "%s" (htmlEscape .anchor) $type }} + {{ if .title }} + {{ $type = .title | htmlEscape }} + {{ if .anchor }} + {{ $type = printf "%s" (htmlEscape .anchor) $type }} + {{ end }} {{ end }} {{ else if reflect.IsMap .additionalProperties }} {{/* @@ -192,6 +190,13 @@ {{ end }} {{ $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 }} {{ return $type }}