From 8bb9918acbbf3d3fe6963379c9ba4acd686cbc69 Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Wed, 28 Oct 2026 21:12:51 +0100 Subject: [PATCH] fix(docui): load Redoc v3 as an ES module, keep v2 with WithRedocV2 Redoc v3 ships its standalone bundle as an ES module, and the "latest" CDN URL now serves it. Loaded with a classic + + +` + + // redocV2Template loads the Redoc v2 bundle, which is a classic UMD script. + // + // The v2 bundle fails when loaded as a module: its wrapper reads properties of the + // top-level "this", which is undefined in a module. + redocV2Template = ` + + + {{ .Title }} + + + + + + + + diff --git a/server-middleware/docui/redoc_test.go b/server-middleware/docui/redoc_test.go index 65ab489b..f8e9e5f0 100644 --- a/server-middleware/docui/redoc_test.go +++ b/server-middleware/docui/redoc_test.go @@ -28,7 +28,48 @@ func TestRedocMiddleware(t *testing.T) { body := recorder.Body.String() assert.StringContainsT(t, body, fmt.Sprintf("%s", defaultDocsTitle)) assert.StringContainsT(t, body, fmt.Sprintf("", defaultDocsURL)) - assert.StringContainsT(t, body, redocLatest) + assert.StringContainsT(t, body, fmt.Sprintf(`` + + h := Redoc(nil, WithRedocV2(), WithUITemplate(tpl)) + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "/docs", nil) + require.NoError(t, err) + recorder := httptest.NewRecorder() + + h.ServeHTTP(recorder, req) + assert.EqualT(t, http.StatusOK, recorder.Code) + assert.StringContainsT(t, recorder.Body.String(), fmt.Sprintf(`