From fec3b46e50abd4e4379dce2188a4f5cbbb49c15a Mon Sep 17 00:00:00 2001 From: Gabriel Radureau Date: Tue, 7 Apr 2026 00:46:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=90=20feat:=20add=20JWT=20authenticati?= =?UTF-8?q?on=20support=20to=20Swagger=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added ApiKeyAuth security definition for JWT Bearer token authentication - Configured security scheme with Authorization header and Bearer token format - Added @Security annotations to greet endpoints (v1 GET, v2 POST) for optional authentication - Updated Swagger documentation to show authentication requirements - Maintained backward compatibility - authentication remains optional for greet endpoints Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- cmd/server/main.go | 5 +++++ pkg/greet/api_v1.go | 2 ++ pkg/greet/api_v2.go | 1 + 3 files changed, 8 insertions(+) diff --git a/cmd/server/main.go b/cmd/server/main.go index a682e76..5ae0db9 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -15,6 +15,11 @@ // @host localhost:8080 // @BasePath /api // @schemes http https +// +// @securityDefinitions.apikey ApiKeyAuth +// @in header +// @name Authorization +// @description JWT authentication using Bearer token. Format: Bearer package main diff --git a/pkg/greet/api_v1.go b/pkg/greet/api_v1.go index 8ec441c..7a65f84 100644 --- a/pkg/greet/api_v1.go +++ b/pkg/greet/api_v1.go @@ -88,6 +88,7 @@ func (h *apiV1GreetHandler) RegisterRoutes(router chi.Router) { // @Accept json // @Produce json // @Success 200 {object} GreetResponse "Successful response" +// @Security ApiKeyAuth // @Router /v1/greet [get] func (h *apiV1GreetHandler) handleGreetQuery(w http.ResponseWriter, r *http.Request) { name := r.URL.Query().Get("name") @@ -104,6 +105,7 @@ func (h *apiV1GreetHandler) handleGreetQuery(w http.ResponseWriter, r *http.Requ // @Param name path string true "Name to greet" // @Success 200 {object} GreetResponse "Successful response" // @Failure 400 {object} ErrorResponse "Invalid name parameter" +// @Security ApiKeyAuth // @Router /v1/greet/{name} [get] func (h *apiV1GreetHandler) handleGreetPath(w http.ResponseWriter, r *http.Request) { name := chi.URLParam(r, "name") diff --git a/pkg/greet/api_v2.go b/pkg/greet/api_v2.go index 105d470..5378546 100644 --- a/pkg/greet/api_v2.go +++ b/pkg/greet/api_v2.go @@ -55,6 +55,7 @@ type greetResponse struct { // @Param request body GreetRequest true "Greeting request" // @Success 200 {object} GreetResponseV2 "Successful response" // @Failure 400 {object} ValidationError "Validation error" +// @Security ApiKeyAuth // @Router /v2/greet [post] func (h *apiV2GreetHandler) handleGreetPost(w http.ResponseWriter, r *http.Request) { // Read request body