From f30e850bf1d8ac192231fc2102fbfb39fed42728 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 10 Dec 2025 20:34:11 +0000 Subject: [PATCH] Fix duplicate modules endpoints I was seeing duplicate endpoints appearing under each module (typically 2 of each). This turned out to be due to the `render-operation` partial being called multiple times (once when rendering the page, and another when rendering the left-hand-side TOC). We now check whether the endpoint has already been added to the list before insertion, via a "seen" map (for quick lookup). --- layouts/_partials/endpoints-toc.html | 19 ++++++++----------- .../_partials/openapi/render-operation.html | 11 +++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/layouts/_partials/endpoints-toc.html b/layouts/_partials/endpoints-toc.html index 88d37a09..740160c6 100644 --- a/layouts/_partials/endpoints-toc.html +++ b/layouts/_partials/endpoints-toc.html @@ -16,9 +16,9 @@ {{/* Sort by module to group visually */}} {{ $sorted := sort $endpoints "module" }} {{ $current := "" }} - {{ $seen := newScratch }} {{ range $sorted }} {{ $mod := .module }} + {{/* Set a title for the base endpoints */}} {{ if not $mod }}{{ $mod = "Required" }}{{ end }} {{ if ne $mod $current }} {{ if $current }}{{ end }} @@ -28,16 +28,13 @@ {{ $current = $mod }} {{ end }} {{ $key := printf "%s|%s" .method .anchor }} - {{ if not ($seen.Get $key) }} - {{ $seen.Set $key true }} -
  • - - {{ .method }} - {{ .endpoint }} - {{ if .deprecated }}(deprecated){{ end }} - -
  • - {{ end }} +
  • + + {{ .method }} + {{ .endpoint }} + {{ if .deprecated }}(deprecated){{ end }} + +
  • {{ end }} {{ if $current }}{{ end }} diff --git a/layouts/_partials/openapi/render-operation.html b/layouts/_partials/openapi/render-operation.html index 7ab30a8f..710993b2 100644 --- a/layouts/_partials/openapi/render-operation.html +++ b/layouts/_partials/openapi/render-operation.html @@ -35,10 +35,21 @@ {{ if $page }} {{/* Store each endpoint's metadata in a scratch variable */}} {{ $entry := dict "anchor" $anchor "method" $method "endpoint" $endpoint "summary" $operation_data.summary "deprecated" $operation_data.deprecated "module" $module }} + {{ if not ($page.Scratch.Get "api_endpoints_seen") }} + {{ $page.Scratch.Set "api_endpoints_seen" dict }} + {{ end }} + {{/* Keep a map of seen endpoints. This is necessary as this partial may be + rendered multiple times for the same endpoint (e.g. in the TOC and + in the main content), leading to duplicates. */}} + {{ $seen := $page.Scratch.Get "api_endpoints_seen" }} + {{ $key := printf "%s|%s" $method $endpoint }} + {{ if not (index $seen $key) }} {{ if not (reflect.IsSlice ($page.Scratch.Get "api_endpoints")) }} {{ $page.Scratch.Set "api_endpoints" (slice) }} {{ end }} {{ $page.Scratch.Add "api_endpoints" (slice $entry) }} + {{ $page.Scratch.SetInMap "api_endpoints_seen" $key true }} + {{ end }} {{ end }}