From 9475e1a2452b7b44bc06d6c3eb0d7766f1231bcd Mon Sep 17 00:00:00 2001 From: Ravi Prasad Date: Wed, 18 Jun 2025 22:32:08 -0500 Subject: [PATCH] swagger update --- controllers/player_advanced_controller.go | 2 +- controllers/player_shot_chart_controller.go | 2 +- controllers/player_total_controller.go | 2 +- docker-compose.yml | 2 +- docs/docs.go | 24 +-------------------- docs/swagger.json | 24 +-------------------- docs/swagger.yaml | 13 +---------- main.go | 16 +++++++++----- 8 files changed, 18 insertions(+), 67 deletions(-) diff --git a/controllers/player_advanced_controller.go b/controllers/player_advanced_controller.go index 1f97649..859afe7 100644 --- a/controllers/player_advanced_controller.go +++ b/controllers/player_advanced_controller.go @@ -59,7 +59,7 @@ func ScrapePlayerAdvancedStats(db *gorm.DB) fiber.Handler { } // GetAllAdvancedPlayerStats godoc -// @Security ApiKeyAuth +// //@Security ApiKeyAuth // @Summary Get player advanced stats // @Description Returns filtered and paginated player advanced stats // @Tags PlayerStats diff --git a/controllers/player_shot_chart_controller.go b/controllers/player_shot_chart_controller.go index e874c1b..eee0a87 100644 --- a/controllers/player_shot_chart_controller.go +++ b/controllers/player_shot_chart_controller.go @@ -67,7 +67,7 @@ func ScrapePlayerShotChart(db *gorm.DB) fiber.Handler { } // GetPlayerShotChart godoc -// @Security ApiKeyAuth +// //@Security ApiKeyAuth // @Summary Get shot-chart data // @Description Returns shot-chart points, optionally filtered by playerId and/or season // @Tags PlayerShotChart diff --git a/controllers/player_total_controller.go b/controllers/player_total_controller.go index 5207288..e8fd708 100644 --- a/controllers/player_total_controller.go +++ b/controllers/player_total_controller.go @@ -57,7 +57,7 @@ func ScrapePlayerTotalStats(db *gorm.DB) fiber.Handler { } // GetPlayerTotalStats godoc -// @Security ApiKeyAuth +// //@Security ApiKeyAuth // @Summary Get player total stats // @Description Filter and paginate player totals // @Tags PlayerTotals diff --git a/docker-compose.yml b/docker-compose.yml index 83834bc..56052f6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: db-init: build: . env_file: .env - command: ["/nba_go", "import-data"] + command: ["/nba_go"] depends_on: postgres: condition: service_healthy diff --git a/docs/docs.go b/docs/docs.go index 7f42d9c..d512093 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -17,11 +17,6 @@ const docTemplate = `{ "paths": { "/api/playeradvancedstats": { "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], "description": "Returns filtered and paginated player advanced stats", "consumes": [ "application/json" @@ -160,11 +155,6 @@ const docTemplate = `{ }, "/api/playershotchart": { "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], "description": "Returns shot-chart points, optionally filtered by playerId and/or season", "consumes": [ "application/json" @@ -281,11 +271,6 @@ const docTemplate = `{ }, "/api/playertotals": { "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], "description": "Filter and paginate player totals", "consumes": [ "application/json" @@ -605,13 +590,6 @@ const docTemplate = `{ } } } - }, - "securityDefinitions": { - "ApiKeyAuth": { - "type": "apiKey", - "name": "X-API-Key", - "in": "header" - } } }` @@ -622,7 +600,7 @@ var SwaggerInfo = &swag.Spec{ BasePath: "/", Schemes: []string{"http", "https"}, Title: "NBA_Go API", - Description: "Stats service with API-key auth", + Description: "Stats service, now with public access!", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/docs/swagger.json b/docs/swagger.json index 4230894..52e5ad2 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -5,7 +5,7 @@ ], "swagger": "2.0", "info": { - "description": "Stats service with API-key auth", + "description": "Stats service, now with public access!", "title": "NBA_Go API", "contact": {}, "version": "1.0" @@ -14,11 +14,6 @@ "paths": { "/api/playeradvancedstats": { "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], "description": "Returns filtered and paginated player advanced stats", "consumes": [ "application/json" @@ -157,11 +152,6 @@ }, "/api/playershotchart": { "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], "description": "Returns shot-chart points, optionally filtered by playerId and/or season", "consumes": [ "application/json" @@ -278,11 +268,6 @@ }, "/api/playertotals": { "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], "description": "Filter and paginate player totals", "consumes": [ "application/json" @@ -602,12 +587,5 @@ } } } - }, - "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 0caa202..29e9641 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -123,7 +123,7 @@ definitions: type: object info: contact: {} - description: Stats service with API-key auth + description: Stats service, now with public access! title: NBA_Go API version: "1.0" paths: @@ -182,8 +182,6 @@ paths: additionalProperties: type: string type: object - security: - - ApiKeyAuth: [] summary: Get player advanced stats tags: - PlayerStats @@ -251,8 +249,6 @@ paths: additionalProperties: type: string type: object - security: - - ApiKeyAuth: [] summary: Get shot-chart data tags: - PlayerShotChart @@ -355,8 +351,6 @@ paths: additionalProperties: type: string type: object - security: - - ApiKeyAuth: [] summary: Get player total stats tags: - PlayerTotals @@ -397,9 +391,4 @@ paths: 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 46671b5..0b66512 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,17 @@ // @title NBA_Go API // @version 1.0 -// @description Stats service with API-key auth +// @description Stats service, now with public access! // @schemes http https // @BasePath / // -// @securityDefinitions.apikey ApiKeyAuth -// @in header -// @name X-API-Key +// To re-enable security docs: +// 1. Uncomment the securityDefinitions block below. +// 2. Uncomment the @Security annotation in each controller. +// 3. Run 'swag init'. +// +// //@securityDefinitions.apikey ApiKeyAuth +// //@in header +// //@name X-API-Key package main import ( @@ -88,7 +93,8 @@ func main() { controllers.RegisterKeyAdminRoutes(app, db) /* ---------- PROTECTED ROUTES ---------- */ - app.Use(middleware.APIKeyAuth(db)) + // Remove Comment to re-enable api key middleware. + // app.Use(middleware.APIKeyAuth(db)) routes.RegisterPlayerAdvancedRoutes(app, db) routes.RegisterPlayerTotalRoutes(app, db) routes.RegisterPlayerShotChartRoutes(app, db)