feat: integrate swag fmt and improve CI/CD workflows
Some checks failed
Go CI/CD Pipeline / Lint and Format (push) Successful in 4m51s
Docker Build and Publish / Version Bump (push) Successful in 4m54s
Docker Build and Publish / Build and Push Docker Image (push) Failing after 2m51s
Go CI/CD Pipeline / Build and Test (push) Successful in 9m47s
Go CI/CD Pipeline / Version Management (push) Successful in 12s
Some checks failed
Go CI/CD Pipeline / Lint and Format (push) Successful in 4m51s
Docker Build and Publish / Version Bump (push) Successful in 4m54s
Docker Build and Publish / Build and Push Docker Image (push) Failing after 2m51s
Go CI/CD Pipeline / Build and Test (push) Successful in 9m47s
Go CI/CD Pipeline / Version Management (push) Successful in 12s
- Add swag fmt to git pre-commit hook and CI/CD pipeline - Create comprehensive CONTRIBUTING.md guide with AI section - Update ADR-0013 with swag fmt documentation - Fix swagger generation to include all endpoints - Improve local testing scripts and workflows - Update Dockerfile for better swagger handling - Fix CI/CD workflow file references
This commit is contained in:
@@ -3,6 +3,7 @@ package bdd
|
||||
import (
|
||||
"DanceLessonsCoach/pkg/bdd/steps"
|
||||
"DanceLessonsCoach/pkg/bdd/testserver"
|
||||
|
||||
"github.com/cucumber/godog"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"DanceLessonsCoach/pkg/config"
|
||||
"DanceLessonsCoach/pkg/server"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
||||
@@ -10,34 +10,39 @@ import (
|
||||
)
|
||||
|
||||
// GreetResponse represents a greeting response
|
||||
// @Description GreetResponse represents a greeting response with a message
|
||||
// @Property message string "The greeting message" example("Hello John!")
|
||||
//
|
||||
// @Description GreetResponse represents a greeting response with a message
|
||||
// @Property message string "The greeting message" example("Hello John!")
|
||||
type GreetResponse struct {
|
||||
Message string `json:"message" example:"Hello John!"`
|
||||
}
|
||||
|
||||
// GreetRequest represents a greeting request
|
||||
// @Description GreetRequest represents a request with a name to greet
|
||||
// @Property name string "The name to greet" example("John")
|
||||
//
|
||||
// @Description GreetRequest represents a request with a name to greet
|
||||
// @Property name string "The name to greet" example("John")
|
||||
type GreetRequest struct {
|
||||
Name string `json:"name" example:"John"`
|
||||
}
|
||||
|
||||
// ErrorResponse represents an error response
|
||||
// @Description ErrorResponse represents an error response
|
||||
//
|
||||
// @Description ErrorResponse represents an error response
|
||||
type ErrorResponse struct {
|
||||
Error string `json:"error" example:"invalid_request"`
|
||||
Message string `json:"message" example:"Invalid name parameter"`
|
||||
}
|
||||
|
||||
// GreetResponseV2 represents a v2 greeting response
|
||||
// @Description GreetResponseV2 represents a v2 greeting response
|
||||
//
|
||||
// @Description GreetResponseV2 represents a v2 greeting response
|
||||
type GreetResponseV2 struct {
|
||||
Message string `json:"message" example:"Hello my friend John!"`
|
||||
}
|
||||
|
||||
// ValidationError represents a validation error response
|
||||
// @Description ValidationError represents a validation error with details
|
||||
//
|
||||
// @Description ValidationError represents a validation error with details
|
||||
type ValidationError struct {
|
||||
Error string `json:"error" example:"validation_failed"`
|
||||
Message string `json:"message" example:"Invalid request data"`
|
||||
@@ -45,7 +50,8 @@ type ValidationError struct {
|
||||
}
|
||||
|
||||
// ValidationDetail represents a single validation error detail
|
||||
// @Description ValidationDetail represents a single field validation error
|
||||
//
|
||||
// @Description ValidationDetail represents a single field validation error
|
||||
type ValidationDetail struct {
|
||||
Field string `json:"field" example:"name"`
|
||||
Error string `json:"error" example:"must be <= 100 characters"`
|
||||
@@ -75,28 +81,30 @@ func (h *apiV1GreetHandler) RegisterRoutes(router chi.Router) {
|
||||
}
|
||||
|
||||
// handleGreetQuery godoc
|
||||
// @Summary Get default greeting
|
||||
// @Description Returns a default greeting message
|
||||
// @Tags API/v1/Greeting
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} GreetResponse "Successful response"
|
||||
// @Router /v1/greet [get]
|
||||
//
|
||||
// @Summary Get default greeting
|
||||
// @Description Returns a default greeting message
|
||||
// @Tags API/v1/Greeting
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} GreetResponse "Successful response"
|
||||
// @Router /v1/greet [get]
|
||||
func (h *apiV1GreetHandler) handleGreetQuery(w http.ResponseWriter, r *http.Request) {
|
||||
name := r.URL.Query().Get("name")
|
||||
h.writeJSONResponse(w, h.greeter.Greet(r.Context(), name))
|
||||
}
|
||||
|
||||
// handleGreetPath godoc
|
||||
// @Summary Get personalized greeting
|
||||
// @Description Returns a greeting with the specified name
|
||||
// @Tags API/v1/Greeting
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param name path string true "Name to greet"
|
||||
// @Success 200 {object} GreetResponse "Successful response"
|
||||
// @Failure 400 {object} ErrorResponse "Invalid name parameter"
|
||||
// @Router /v1/greet/{name} [get]
|
||||
//
|
||||
// @Summary Get personalized greeting
|
||||
// @Description Returns a greeting with the specified name
|
||||
// @Tags API/v1/Greeting
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param name path string true "Name to greet"
|
||||
// @Success 200 {object} GreetResponse "Successful response"
|
||||
// @Failure 400 {object} ErrorResponse "Invalid name parameter"
|
||||
// @Router /v1/greet/{name} [get]
|
||||
func (h *apiV1GreetHandler) handleGreetPath(w http.ResponseWriter, r *http.Request) {
|
||||
name := chi.URLParam(r, "name")
|
||||
h.writeJSONResponse(w, h.greeter.Greet(r.Context(), name))
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"DanceLessonsCoach/pkg/validation"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
@@ -45,15 +46,16 @@ type greetResponse struct {
|
||||
}
|
||||
|
||||
// handleGreetPost godoc
|
||||
// @Summary Get greeting (v2)
|
||||
// @Description Returns a greeting message with validation (v2)
|
||||
// @Tags API/v2/Greeting
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body GreetRequest true "Greeting request"
|
||||
// @Success 200 {object} GreetResponseV2 "Successful response"
|
||||
// @Failure 400 {object} ValidationError "Validation error"
|
||||
// @Router /v2/greet [post]
|
||||
//
|
||||
// @Summary Get greeting (v2)
|
||||
// @Description Returns a greeting message with validation (v2)
|
||||
// @Tags API/v2/Greeting
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body GreetRequest true "Greeting request"
|
||||
// @Success 200 {object} GreetResponseV2 "Successful response"
|
||||
// @Failure 400 {object} ValidationError "Validation error"
|
||||
// @Router /v2/greet [post]
|
||||
func (h *apiV2GreetHandler) handleGreetPost(w http.ResponseWriter, r *http.Request) {
|
||||
// Read request body
|
||||
body, err := io.ReadAll(r.Body)
|
||||
|
||||
@@ -2,6 +2,7 @@ package greet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package greet
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:generate swag init -g ../../cmd/server/main.go --parseDependency --parseInternal
|
||||
//go:generate swag init -g ../../cmd/server/main.go -d ../../pkg/greet,../../pkg/server --parseDependency && mv ../../docs/* ./docs/
|
||||
|
||||
package server
|
||||
|
||||
@@ -139,27 +139,29 @@ func (s *Server) getAllMiddlewares() []func(http.Handler) http.Handler {
|
||||
}
|
||||
|
||||
// handleHealth godoc
|
||||
// @Summary Health check
|
||||
// @Description Check if the service is healthy
|
||||
// @Tags System/Health
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]string "Service is healthy"
|
||||
// @Router /health [get]
|
||||
//
|
||||
// @Summary Health check
|
||||
// @Description Check if the service is healthy
|
||||
// @Tags System/Health
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]string "Service is healthy"
|
||||
// @Router /health [get]
|
||||
func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
|
||||
log.Trace().Msg("Health check requested")
|
||||
w.Write([]byte(`{"status":"healthy"}`))
|
||||
}
|
||||
|
||||
// handleReadiness godoc
|
||||
// @Summary Readiness check
|
||||
// @Description Check if the service is ready to accept traffic
|
||||
// @Tags System/Health
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]bool "Service is ready"
|
||||
// @Failure 503 {object} map[string]bool "Service is not ready"
|
||||
// @Router /ready [get]
|
||||
//
|
||||
// @Summary Readiness check
|
||||
// @Description Check if the service is ready to accept traffic
|
||||
// @Tags System/Health
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} map[string]bool "Service is ready"
|
||||
// @Failure 503 {object} map[string]bool "Service is not ready"
|
||||
// @Router /ready [get]
|
||||
func (s *Server) handleReadiness(w http.ResponseWriter, r *http.Request) {
|
||||
log.Trace().Msg("Readiness check requested")
|
||||
|
||||
@@ -175,14 +177,15 @@ func (s *Server) handleReadiness(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// handleVersion godoc
|
||||
// @Summary Get API version
|
||||
// @Description Returns the API version information
|
||||
// @Tags System/Version
|
||||
// @Accept plain,json
|
||||
// @Produce plain,json
|
||||
// @Param format query string false "Response format (plain, full, json)" Enums(plain, full, json) default(plain)
|
||||
// @Success 200 {string} string "Version information"
|
||||
// @Router /version [get]
|
||||
//
|
||||
// @Summary Get API version
|
||||
// @Description Returns the API version information
|
||||
// @Tags System/Version
|
||||
// @Accept plain,json
|
||||
// @Produce plain,json
|
||||
// @Param format query string false "Response format (plain, full, json)" Enums(plain, full, json) default(plain)
|
||||
// @Success 200 {string} string "Version information"
|
||||
// @Router /version [get]
|
||||
func (s *Server) handleVersion(w http.ResponseWriter, r *http.Request) {
|
||||
log.Trace().Msg("Version check requested")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user