Add swaggo annotations to all handlers and regenerate full Swagger docs
- Added @Summary/@Router/@Param/@Success/@Security annotations to all API handlers - Regenerated docs/swagger.json, docs/swagger.yaml, docs/docs.go with full endpoint definitions - Fixed generated docs.go to remove unsupported LeftDelim/RightDelim fields
This commit is contained in:
@@ -78,6 +78,16 @@ func gravatarURL(email string) string {
|
||||
return fmt.Sprintf("https://www.gravatar.com/avatar/%s?d=identicon&s=256", hex.EncodeToString(hash[:]))
|
||||
}
|
||||
|
||||
// @Summary Register a new user
|
||||
// @Description Create a new user account
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body registerRequest true "Registration data"
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Failure 400 {object} map[string]string
|
||||
// @Failure 409 {object} map[string]string
|
||||
// @Router /auth/register [post]
|
||||
func (h *Handler) Register(w http.ResponseWriter, r *http.Request) {
|
||||
var req registerRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
@@ -123,6 +133,16 @@ func (h *Handler) Register(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(map[string]string{"id": userID})
|
||||
}
|
||||
|
||||
// @Summary Login with email and password
|
||||
// @Description Authenticate with email and password
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body loginRequest true "Login credentials"
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Failure 400 {object} map[string]string
|
||||
// @Failure 401 {object} map[string]string
|
||||
// @Router /auth/login/password [post]
|
||||
func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
|
||||
var req loginRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
@@ -156,6 +176,11 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(map[string]string{"id": userID})
|
||||
}
|
||||
|
||||
// @Summary Logout
|
||||
// @Description End the current session
|
||||
// @Tags auth
|
||||
// @Success 204
|
||||
// @Router /auth/logout [post]
|
||||
func (h *Handler) Logout(w http.ResponseWriter, r *http.Request) {
|
||||
cookie, err := r.Cookie(h.cfg.Session.CookieName)
|
||||
if err == nil {
|
||||
@@ -173,6 +198,14 @@ func (h *Handler) Logout(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// @Summary Get current user profile
|
||||
// @Description Get the authenticated user's profile
|
||||
// @Tags auth
|
||||
// @Produce json
|
||||
// @Security SessionAuth
|
||||
// @Success 200 {object} UserProfile
|
||||
// @Failure 401 {object} map[string]string
|
||||
// @Router /auth/me [get]
|
||||
func (h *Handler) Me(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := middleware.UserIDFromContext(r.Context())
|
||||
if !ok {
|
||||
@@ -190,6 +223,17 @@ func (h *Handler) Me(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(user)
|
||||
}
|
||||
|
||||
// @Summary Update current user profile
|
||||
// @Description Update the authenticated user's profile
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security SessionAuth
|
||||
// @Param body body updateProfileRequest true "Profile update data"
|
||||
// @Success 200 {object} UserProfile
|
||||
// @Failure 400 {object} map[string]string
|
||||
// @Failure 401 {object} map[string]string
|
||||
// @Router /auth/me [patch]
|
||||
func (h *Handler) UpdateProfile(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := middleware.UserIDFromContext(r.Context())
|
||||
if !ok {
|
||||
|
||||
@@ -88,6 +88,16 @@ func (h *WebAuthnHandler) RegisterRoutes(r *http.ServeMux) {
|
||||
r.HandleFunc("POST /auth/webauthn/login/finish", h.LoginFinish)
|
||||
}
|
||||
|
||||
// @Summary Begin passkey registration
|
||||
// @Description Start passkey registration for an authenticated user
|
||||
// @Tags webauthn
|
||||
// @Produce json
|
||||
// @Security SessionAuth
|
||||
// @Success 200 {object} object "WebAuthn registration options"
|
||||
// @Failure 401 {object} map[string]string
|
||||
// @Failure 404 {object} map[string]string
|
||||
// @Failure 500 {object} map[string]string
|
||||
// @Router /auth/webauthn/register/begin [post]
|
||||
// RegisterBegin starts passkey registration for an authenticated user.
|
||||
func (h *WebAuthnHandler) RegisterBegin(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := middleware.UserIDFromContext(r.Context())
|
||||
@@ -116,6 +126,16 @@ func (h *WebAuthnHandler) RegisterBegin(w http.ResponseWriter, r *http.Request)
|
||||
json.NewEncoder(w).Encode(options)
|
||||
}
|
||||
|
||||
// @Summary Finish passkey registration
|
||||
// @Description Complete passkey registration
|
||||
// @Tags webauthn
|
||||
// @Produce json
|
||||
// @Security SessionAuth
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Failure 400 {object} map[string]string
|
||||
// @Failure 401 {object} map[string]string
|
||||
// @Failure 500 {object} map[string]string
|
||||
// @Router /auth/webauthn/register/finish [post]
|
||||
// RegisterFinish completes passkey registration.
|
||||
func (h *WebAuthnHandler) RegisterFinish(w http.ResponseWriter, r *http.Request) {
|
||||
userID, ok := middleware.UserIDFromContext(r.Context())
|
||||
@@ -163,6 +183,13 @@ func (h *WebAuthnHandler) RegisterFinish(w http.ResponseWriter, r *http.Request)
|
||||
json.NewEncoder(w).Encode(map[string]string{"status": "registered"})
|
||||
}
|
||||
|
||||
// @Summary Begin passkey login
|
||||
// @Description Start passkey authentication
|
||||
// @Tags webauthn
|
||||
// @Produce json
|
||||
// @Success 200 {object} object "WebAuthn login options"
|
||||
// @Failure 500 {object} map[string]string
|
||||
// @Router /auth/webauthn/login/begin [post]
|
||||
// LoginBegin starts passkey authentication (no auth required).
|
||||
func (h *WebAuthnHandler) LoginBegin(w http.ResponseWriter, r *http.Request) {
|
||||
// Get all registered credentials for the login ceremony
|
||||
@@ -213,6 +240,15 @@ func (h *WebAuthnHandler) LoginBegin(w http.ResponseWriter, r *http.Request) {
|
||||
json.NewEncoder(w).Encode(options)
|
||||
}
|
||||
|
||||
// @Summary Finish passkey login
|
||||
// @Description Complete passkey authentication
|
||||
// @Tags webauthn
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Failure 400 {object} map[string]string
|
||||
// @Failure 401 {object} map[string]string
|
||||
// @Router /auth/webauthn/login/finish [post]
|
||||
// LoginFinish completes passkey authentication.
|
||||
func (h *WebAuthnHandler) LoginFinish(w http.ResponseWriter, r *http.Request) {
|
||||
// Get challenge key from cookie
|
||||
|
||||
Reference in New Issue
Block a user