swagger fixed

This commit is contained in:
Ravi Prasad
2025-05-08 17:11:25 -05:00
parent 8c577b441c
commit 1d3edc68b4
8 changed files with 119 additions and 56 deletions
Vendored
BIN
View File
Binary file not shown.
-27
View File
@@ -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 APIkey 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`)
// ------------------------------------------------------------
+12 -5
View File
@@ -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 // SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{ var SwaggerInfo = &swag.Spec{
Version: "", Version: "1.0",
Host: "", Host: "",
BasePath: "", BasePath: "/",
Schemes: []string{}, Schemes: []string{"http", "https"},
Title: "", Title: "NBA_Go API",
Description: "", Description: "Stats service with API-key auth",
InfoInstanceName: "swagger", InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate, SwaggerTemplate: docTemplate,
LeftDelim: "{{", LeftDelim: "{{",
+16 -1
View File
@@ -1,8 +1,16 @@
{ {
"schemes": [
"http",
"https"
],
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {
"contact": {} "description": "Stats service with API-key auth",
"title": "NBA_Go API",
"contact": {},
"version": "1.0"
}, },
"basePath": "/",
"paths": { "paths": {
"/api/playeradvancedstats": { "/api/playeradvancedstats": {
"get": { "get": {
@@ -163,5 +171,12 @@
} }
} }
} }
},
"securityDefinitions": {
"ApiKeyAuth": {
"type": "apiKey",
"name": "X-API-Key",
"in": "header"
}
} }
} }
+12
View File
@@ -1,5 +1,9 @@
basePath: /
info: info:
contact: {} contact: {}
description: Stats service with API-key auth
title: NBA_Go API
version: "1.0"
paths: paths:
/api/playeradvancedstats: /api/playeradvancedstats:
get: get:
@@ -105,4 +109,12 @@ paths:
summary: Get player total stats summary: Get player total stats
tags: tags:
- PlayerTotals - PlayerTotals
schemes:
- http
- https
securityDefinitions:
ApiKeyAuth:
in: header
name: X-API-Key
type: apiKey
swagger: "2.0" swagger: "2.0"
+32 -23
View File
@@ -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 package main
import ( import (
@@ -13,7 +22,7 @@ import (
"github.com/gofiber/fiber/v2/middleware/adaptor" "github.com/gofiber/fiber/v2/middleware/adaptor"
"github.com/gofiber/fiber/v2/middleware/logger" "github.com/gofiber/fiber/v2/middleware/logger"
"github.com/nprasad2077/NBA_Go/config" "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/controllers"
"github.com/nprasad2077/NBA_Go/routes" "github.com/nprasad2077/NBA_Go/routes"
"github.com/nprasad2077/NBA_Go/utils/middleware" "github.com/nprasad2077/NBA_Go/utils/middleware"
@@ -58,29 +67,29 @@ func main() {
routes.RegisterPlayerTotalRoutes(app, db) routes.RegisterPlayerTotalRoutes(app, db)
/* ---------- Optional import job ---------- */ /* ---------- Optional import job ---------- */
go func() { // go func() {
for season := 2023; season <= 2025; season++ { // for season := 2023; season <= 2025; season++ {
if err := services.FetchAndStorePlayerAdvancedStats(db, season); err != nil { // if err := services.FetchAndStorePlayerAdvancedStats(db, season); err != nil {
log.Printf("Fetch failed for player advanced season %d: %v\n", season, err) // log.Printf("Fetch failed for player advanced season %d: %v\n", season, err)
} else { // } else {
log.Printf("Fetch successful for player advanced season %d\n", season) // log.Printf("Fetch successful for player advanced season %d\n", season)
} // }
time.Sleep(1100 * time.Millisecond) // optional delay // time.Sleep(1100 * time.Millisecond) // optional delay
} // }
log.Printf("player advanced Import Success") // log.Printf("player advanced Import Success")
}() // }()
go func() { // go func() {
for season := 2023; season <= 2025; season++ { // for season := 2023; season <= 2025; season++ {
if err := services.FetchAndStorePlayerTotalStats(db, season); err != nil { // if err := services.FetchAndStorePlayerTotalStats(db, season); err != nil {
log.Printf("Fetch failed for player totals season %d: %v\n", season, err) // log.Printf("Fetch failed for player totals season %d: %v\n", season, err)
} else { // } else {
log.Printf("Fetch successful for player totals season %d\n", season) // log.Printf("Fetch successful for player totals season %d\n", season)
} // }
time.Sleep(1000 * time.Millisecond) // optional delay // time.Sleep(1000 * time.Millisecond) // optional delay
} // }
log.Printf("player totals Import Success") // log.Printf("player totals Import Success")
}() // }()
/* ---------- START & SHUTDOWN ---------- */ /* ---------- START & SHUTDOWN ---------- */
go func() { go func() {
+24
View File
@@ -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 APIkey auth
// @schemes http https
// @BasePath /
//
// -----------------------------------------------------------------------------
// 🔐 SECURITY
// -----------------------------------------------------------------------------
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name X-API-Key
//
// (each protected handler still needs `@Security ApiKeyAuth`)
// -----------------------------------------------------------------------------
+23
View File
@@ -0,0 +1,23 @@
// swagger/swagger_doc.go
package main
// -----------------------------------------------------------------------------
// Global Swagger metadata
// -----------------------------------------------------------------------------
// @title NBA_Go API
// @version 1.0
// @description Stats service with APIkey auth
// @schemes http https
// @BasePath /
//
// -----------------------------------------------------------------------------
// 🔐 SECURITY
// -----------------------------------------------------------------------------
// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name X-API-Key
//
// (each protected handler should still add `@Security ApiKeyAuth`)
// -----------------------------------------------------------------------------