From 1d3edc68b4ab2e09eb7a71dbd8fdcd4ea1466a07 Mon Sep 17 00:00:00 2001 From: Ravi Prasad Date: Thu, 8 May 2025 17:11:25 -0500 Subject: [PATCH] swagger fixed --- .DS_Store | Bin 0 -> 8196 bytes docs/api_doc.go | 27 -------------------- docs/docs.go | 17 +++++++++---- docs/swagger.json | 17 ++++++++++++- docs/swagger.yaml | 12 +++++++++ main.go | 55 ++++++++++++++++++++++++----------------- swagger/meta.go | 24 ++++++++++++++++++ swagger/swagger_doc.go | 23 +++++++++++++++++ 8 files changed, 119 insertions(+), 56 deletions(-) create mode 100644 .DS_Store delete mode 100644 docs/api_doc.go create mode 100644 swagger/meta.go create mode 100644 swagger/swagger_doc.go diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..678b385f4791773ac0cdee1a6145222f4e9b4faf GIT binary patch literal 8196 zcmeHMT}&KR6u#d;VWu#0f!0EYg|*n0P)KQG{VRo~fEHVXlm(Wpk?!scFgncQ&g??# zgJ?7wqei3A#25eKn}0EBQZ+`aFUA^;4Vq{Zeel7=YK#wkP+vTEW@uQDH)E=uo7{Wm zo_o%md%yY4+`Y4mF&xb6dl;)@jLB4mgwO0wDq+0wDq+0wDsI0|K;Xiz2VH@B5=+8zK-Qa77{@-Vaf#LdF8Q=u7X_L5+6= zAX!Rkuh2CY7bK&Bj0JMhmo!2JzAH)J6~Pe$zB}oofn6++i@x;T8G^$Hg2)I?DDa}w z{iB{aL(G?98zK-QuoeMvb}wZ*OEH(FR-WI}bC&729UbQ(m6UEME0>jx6_x5$+SqvI zSVB!EQwwop!5uMA8k4-rnaR!%WU}^f&M271{CFm7O^Rwi$yT%*UbgfZ!= zoJ=ljS;JY!bj_?iG0AI$)6ksgIb%l7A(?Pj+`Y&?k#w>-x7Uj>$$8!}jv5reEEs(h z#z~ko4-u(3*6J@;d84W>vTet%j(sPiyu_<(YSqo^mhpn=m}$!xoi}xNW+LTe z3|lwt>7=O}wrftAMoy{5uS(ob%^FL!)iu0+tEMILY4e`E>7L-tvg~Oan>6(foq`W$ zb>XG+Q?lZXG&gD5F)`AcGpN-Ahn+2&8h2=pJQWzWwX16UZqwGeqxi0S_Nv;bl}Z~H z*A+j`^*5;6c)`bq9}blJJ5?=_$)`S z4lm#(yo^`y8cyLf-od;080WBrukba#$4|I`pK(ztmt;wiYNQ4!A~i}or534G+9h>K z-O?dxLYk7M{kcoQro@gFFIJkP{>to{^S_QsAFPvIk%8MP2M())|E28urb=*O)8?zU z)LkQz?53{XOMLVRyv*5^nc&gChzcJ4y;NJp+a=1nhDf6tT`ylpDQ}DgS&*NX`_|3s zcA4^qZ}7VOROP3n9 zYW3YQRpm^)6BPeW{gGQ`$}2AawfT;cu9>$Y+3Qyx1JWF(ckq9s7{yN^oTX-Aq;eC9FGx!K+@fkkH z7xjTrzy9}s&nRp{ z1VRMWD@sUD{)im+SsrRPFT(T4!)U;4w4uA^isd}4uI^d)Ji V{OcbA=(j|;|A+g(N4_h#`3q3a_r3rC literal 0 HcmV?d00001 diff --git a/docs/api_doc.go b/docs/api_doc.go deleted file mode 100644 index fabe709..0000000 --- a/docs/api_doc.go +++ /dev/null @@ -1,27 +0,0 @@ -//go:build docs -// +build docs - -// Package docs Only contains Swagger annotations that are **global**. -// Run `swag init --parseDependency --parseInternal` after editing. -package docs - -// ------------------------------------------------------------ -// General API meta (kept here so CI can inject version/build). -// ------------------------------------------------------------ - -// @title NBA_Go API -// @version 1.0 -// @description Stats service with API‑key auth -// @BasePath / -// @schemes http https - -// ------------------------------------------------------------ -// 🔐 SECURITY – this block is what you asked for -// ------------------------------------------------------------ -// -// @securityDefinitions.apikey ApiKeyAuth -// @in header -// @name X-API-Key -// -// (every protected endpoint still needs `@Security ApiKeyAuth`) -// ------------------------------------------------------------ \ No newline at end of file diff --git a/docs/docs.go b/docs/docs.go index 7e18700..2a0179c 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -174,17 +174,24 @@ const docTemplate = `{ } } } + }, + "securityDefinitions": { + "ApiKeyAuth": { + "type": "apiKey", + "name": "X-API-Key", + "in": "header" + } } }` // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "", + Version: "1.0", Host: "", - BasePath: "", - Schemes: []string{}, - Title: "", - Description: "", + BasePath: "/", + Schemes: []string{"http", "https"}, + Title: "NBA_Go API", + Description: "Stats service with API-key auth", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/docs/swagger.json b/docs/swagger.json index 60820de..92ccf64 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1,8 +1,16 @@ { + "schemes": [ + "http", + "https" + ], "swagger": "2.0", "info": { - "contact": {} + "description": "Stats service with API-key auth", + "title": "NBA_Go API", + "contact": {}, + "version": "1.0" }, + "basePath": "/", "paths": { "/api/playeradvancedstats": { "get": { @@ -163,5 +171,12 @@ } } } + }, + "securityDefinitions": { + "ApiKeyAuth": { + "type": "apiKey", + "name": "X-API-Key", + "in": "header" + } } } \ No newline at end of file diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 736d0b4..028c8ed 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1,5 +1,9 @@ +basePath: / info: contact: {} + description: Stats service with API-key auth + title: NBA_Go API + version: "1.0" paths: /api/playeradvancedstats: get: @@ -105,4 +109,12 @@ paths: summary: Get player total stats tags: - PlayerTotals +schemes: +- http +- https +securityDefinitions: + ApiKeyAuth: + in: header + name: X-API-Key + type: apiKey swagger: "2.0" diff --git a/main.go b/main.go index cb430a2..b8fc453 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,12 @@ +// @title NBA_Go API +// @version 1.0 +// @description Stats service with API-key auth +// @schemes http https +// @BasePath / +// +// @securityDefinitions.apikey ApiKeyAuth +// @in header +// @name X-API-Key package main import ( @@ -13,7 +22,7 @@ import ( "github.com/gofiber/fiber/v2/middleware/adaptor" "github.com/gofiber/fiber/v2/middleware/logger" "github.com/nprasad2077/NBA_Go/config" - "github.com/nprasad2077/NBA_Go/services" + // "github.com/nprasad2077/NBA_Go/services" "github.com/nprasad2077/NBA_Go/controllers" "github.com/nprasad2077/NBA_Go/routes" "github.com/nprasad2077/NBA_Go/utils/middleware" @@ -58,29 +67,29 @@ func main() { routes.RegisterPlayerTotalRoutes(app, db) /* ---------- Optional import job ---------- */ - go func() { - for season := 2023; season <= 2025; season++ { - if err := services.FetchAndStorePlayerAdvancedStats(db, season); err != nil { - log.Printf("Fetch failed for player advanced season %d: %v\n", season, err) - } else { - log.Printf("Fetch successful for player advanced season %d\n", season) - } - time.Sleep(1100 * time.Millisecond) // optional delay - } - log.Printf("player advanced Import Success") - }() + // go func() { + // for season := 2023; season <= 2025; season++ { + // if err := services.FetchAndStorePlayerAdvancedStats(db, season); err != nil { + // log.Printf("Fetch failed for player advanced season %d: %v\n", season, err) + // } else { + // log.Printf("Fetch successful for player advanced season %d\n", season) + // } + // time.Sleep(1100 * time.Millisecond) // optional delay + // } + // log.Printf("player advanced Import Success") + // }() - go func() { - for season := 2023; season <= 2025; season++ { - if err := services.FetchAndStorePlayerTotalStats(db, season); err != nil { - log.Printf("Fetch failed for player totals season %d: %v\n", season, err) - } else { - log.Printf("Fetch successful for player totals season %d\n", season) - } - time.Sleep(1000 * time.Millisecond) // optional delay - } - log.Printf("player totals Import Success") - }() + // go func() { + // for season := 2023; season <= 2025; season++ { + // if err := services.FetchAndStorePlayerTotalStats(db, season); err != nil { + // log.Printf("Fetch failed for player totals season %d: %v\n", season, err) + // } else { + // log.Printf("Fetch successful for player totals season %d\n", season) + // } + // time.Sleep(1000 * time.Millisecond) // optional delay + // } + // log.Printf("player totals Import Success") + // }() /* ---------- START & SHUTDOWN ---------- */ go func() { diff --git a/swagger/meta.go b/swagger/meta.go new file mode 100644 index 0000000..3c2c510 --- /dev/null +++ b/swagger/meta.go @@ -0,0 +1,24 @@ +// Package main holds the global Swagger annotations. +// Run “swag init --parseDependency --parseInternal” after editing. +package main + +// ----------------------------------------------------------------------------- +// General API information +// ----------------------------------------------------------------------------- + +// @title NBA_Go API +// @version 1.0 +// @description Stats service with API‑key auth +// @schemes http https +// @BasePath / + +// +// ----------------------------------------------------------------------------- +// 🔐 SECURITY +// ----------------------------------------------------------------------------- +// @securityDefinitions.apikey ApiKeyAuth +// @in header +// @name X-API-Key +// +// (each protected handler still needs `@Security ApiKeyAuth`) +// ----------------------------------------------------------------------------- \ No newline at end of file diff --git a/swagger/swagger_doc.go b/swagger/swagger_doc.go new file mode 100644 index 0000000..8ba5d02 --- /dev/null +++ b/swagger/swagger_doc.go @@ -0,0 +1,23 @@ +// swagger/swagger_doc.go +package main + +// ----------------------------------------------------------------------------- +// Global Swagger metadata +// ----------------------------------------------------------------------------- + +// @title NBA_Go API +// @version 1.0 +// @description Stats service with API‑key auth +// @schemes http https +// @BasePath / + +// +// ----------------------------------------------------------------------------- +// 🔐 SECURITY +// ----------------------------------------------------------------------------- +// @securityDefinitions.apikey ApiKeyAuth +// @in header +// @name X-API-Key +// +// (each protected handler should still add `@Security ApiKeyAuth`) +// ----------------------------------------------------------------------------- \ No newline at end of file