From 879586c24061a71c511cc0d4b404533d349fe63c Mon Sep 17 00:00:00 2001 From: Paul Schifferer Date: Sat, 2 Nov 2024 09:45:04 -0700 Subject: [PATCH] Update Swagger info --- cmd/catalog-api/main.go | 38 ++++++++++++++++++------- kubernetes/overlays/dev/configmaps.yaml | 3 ++ server/contributions.go | 6 ++-- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/cmd/catalog-api/main.go b/cmd/catalog-api/main.go index 2e9ec4c..f65c363 100644 --- a/cmd/catalog-api/main.go +++ b/cmd/catalog-api/main.go @@ -19,7 +19,7 @@ import ( apiconstants "github.com/sweetrpg/api-core/constants" "github.com/sweetrpg/api-core/tracing" "github.com/sweetrpg/catalog-api/constants" - _ "github.com/sweetrpg/catalog-api/docs" + "github.com/sweetrpg/catalog-api/docs" "github.com/sweetrpg/catalog-api/server" "github.com/sweetrpg/common/logging" "github.com/sweetrpg/common/util" @@ -29,16 +29,13 @@ import ( // @title Catalog API service // @version 1.0 -// @description Testing Swagger APIs. -// @termsOfService http://swagger.io/terms/ +// @description Swagger APIs +// @termsOfService https://pilgrimagesoftware.com/terms/ // @contact.name API Support -// @contact.url http://www.swagger.io/support -// @contact.email support@swagger.io +// @contact.url https://sweetrpg.com +// @contact.email admin@sweetrpg.com // @license.name MIT // @license.url https://mit-license.org/ -// @host localhost:8000 -// @BasePath / -// @schemes http https func main() { _ = godotenv.Load(".env") @@ -62,15 +59,28 @@ func main() { // Actuator setupAcuator(r) - // swagger middleware to serve the API docs - r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) + // Swagger + setupSwagger(r) server.SetupHandlers(r, cache) _ = r.Run(util.GetEnv(apiconstants.BIND_ADDRESS, ":8000")) } +func setupSwagger(r *gin.Engine) { + logging.Logger.Info("Setting up Swagger...") + + docs.SwaggerInfo.Version = os.Getenv(apiconstants.VERSION) + docs.SwaggerInfo.Host = util.GetEnv(apiconstants.INGRESS_HOST, "localhost") + docs.SwaggerInfo.BasePath = util.GetEnv(apiconstants.INGRESS_BASE_PATH, "/") + docs.SwaggerInfo.Schemes = strings.Split(util.GetEnv(apiconstants.INGRESS_SCHEMES, "http"), ",") + // swagger middleware to serve the API docs + r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler)) +} + func setupSentry() { + logging.Logger.Info("Setting up Sentry...") + sentryDsn, found := os.LookupEnv(apiconstants.SENTRY_DSN) if found { sentryDebug, _ := strconv.ParseBool(util.GetEnv(apiconstants.SENTRY_DEBUG, "false")) @@ -100,6 +110,8 @@ func setupSentry() { } func setupAcuator(r *gin.Engine) { + logging.Logger.Info("Setting up actuator...") + actuatorHandler := actuator.GetActuatorHandler(&actuator.Config{ Endpoints: []int{ actuator.Env, @@ -121,6 +133,8 @@ func setupAcuator(r *gin.Engine) { } func setupCache() persistence.CacheStore { + logging.Logger.Info("Setting up query cache...") + var cache persistence.CacheStore redisHost, found := os.LookupEnv(apiconstants.REDIS_HOST) if found { @@ -136,12 +150,16 @@ func setupCache() persistence.CacheStore { } func setupTracing(r *gin.Engine) { + logging.Logger.Info("Setting up tracing...") + tracing.SetupTracing(constants.ServiceName) defer tracing.TeardownTracing() r.Use(otelgin.Middleware(constants.ServiceName)) } func setupMetrics(r *gin.Engine) { + logging.Logger.Info("Setting up metrics endpoint...") + m := ginmetrics.GetMonitor() m.SetMetricPath("/metrics") m.SetSlowTime(10) diff --git a/kubernetes/overlays/dev/configmaps.yaml b/kubernetes/overlays/dev/configmaps.yaml index e9a700d..54a4a18 100644 --- a/kubernetes/overlays/dev/configmaps.yaml +++ b/kubernetes/overlays/dev/configmaps.yaml @@ -19,3 +19,6 @@ data: OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger-collector.observability.svc.cluster.local:4318/ SENTRY_RELEASE: "1" REDIS_HOST: redis-master.sweetrpg-catalog.svc.cluster.local + INGRESS_BASE_PATH: /0 + INGRESS_HOST: api.catalog.dev.sweetrpg.com + INGRESS_SCHEMES: http,https diff --git a/server/contributions.go b/server/contributions.go index 53a070a..ba927e3 100644 --- a/server/contributions.go +++ b/server/contributions.go @@ -5,13 +5,13 @@ import ( "net/http" "time" - "github.com/sweetrpg/api-core/tracing" - "github.com/getsentry/sentry-go" "github.com/gin-contrib/cache" "github.com/gin-contrib/cache/persistence" "github.com/gin-gonic/gin" "github.com/google/jsonapi" + "github.com/sweetrpg/api-core/tracing" + _ "github.com/sweetrpg/api-core/vo" "github.com/sweetrpg/catalog-data/data" "github.com/sweetrpg/common/logging" options "go.jtlabs.io/query" @@ -35,7 +35,7 @@ func setupContributionHandlers(g *gin.Engine, store persistence.CacheStore) { // @Tags contributions // @Produce json // @Success 200 {object} interface{} -// @Failure 500 {object} interface{} +// @Failure 500 {object} vo.ErrorVO // @Router /contributions [get] func listContributions(c *gin.Context) { opt, _ := options.FromQuerystring(c.Request.URL.RawQuery)