Skip to content

Commit e112624

Browse files
author
Amine Afia
committed
Integrate swagger docs
1 parent 47272d6 commit e112624

File tree

9 files changed

+2750
-8
lines changed

9 files changed

+2750
-8
lines changed

api/api.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,63 @@ import (
1313
"github.com/rs/zerolog/log"
1414
)
1515

16+
// Error represents an API error response
17+
// @Description Error represents an API error response
1618
type Error struct {
19+
// @Description HTTP status code
1720
Code int `json:"code"`
21+
// @Description Error message
1822
Message string `json:"message"`
23+
// @Description Support ID for tracking the error
1924
SupportId string `json:"support_id"`
2025
}
2126

27+
// QueryParams represents the parameters for querying data
28+
// @Description QueryParams represents the parameters for querying data
2229
type QueryParams struct {
30+
// @Description Map of filter parameters
2331
FilterParams map[string]string `schema:"-"`
32+
// @Description Field to group results by
2433
GroupBy string `schema:"group_by"`
34+
// @Description Field to sort results by
2535
SortBy string `schema:"sort_by"`
36+
// @Description Sort order (asc or desc)
2637
SortOrder string `schema:"sort_order"`
38+
// @Description Page number for pagination
2739
Page int `schema:"page"`
40+
// @Description Number of items per page
2841
Limit int `schema:"limit"`
42+
// @Description List of aggregate functions to apply
2943
Aggregates []string `schema:"aggregate"`
3044
}
3145

46+
// Meta represents metadata for a query response
47+
// @Description Meta represents metadata for a query response
3248
type Meta struct {
49+
// @Description Chain ID of the blockchain
3350
ChainId uint64 `json:"chain_id"`
51+
// @Description Contract address
3452
ContractAddress string `json:"address"`
53+
// @Description Function or event signature
3554
Signature string `json:"signature"`
55+
// @Description Current page number
3656
Page int `json:"page"`
57+
// @Description Number of items per page
3758
Limit int `json:"limit"`
59+
// @Description Total number of items
3860
TotalItems int `json:"total_items"`
61+
// @Description Total number of pages
3962
TotalPages int `json:"total_pages"`
4063
}
4164

65+
// QueryResponse represents the response structure for a query
66+
// @Description QueryResponse represents the response structure for a query
4267
type QueryResponse struct {
68+
// @Description Metadata for the query response
4369
Meta Meta `json:"meta"`
70+
// @Description Query result data
4471
Data interface{} `json:"data,omitempty"`
72+
// @Description Aggregation results
4573
Aggregations map[string]string `json:"aggregations,omitempty"`
4674
}
4775

cmd/api.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import (
55

66
"github.com/gin-gonic/gin"
77
"github.com/spf13/cobra"
8+
swaggerFiles "github.com/swaggo/files"
9+
ginSwagger "github.com/swaggo/gin-swagger"
810

911
"github.com/thirdweb-dev/indexer/internal/handlers"
1012
"github.com/thirdweb-dev/indexer/internal/middleware"
13+
14+
// Import the generated Swagger docs
15+
_ "github.com/thirdweb-dev/indexer/docs"
1116
)
1217

1318
var (
@@ -21,11 +26,31 @@ var (
2126
}
2227
)
2328

29+
// @title Thirdweb Insight
30+
// @version 0.0.1
31+
// @description API for querying blockchain transactions and events
32+
// @termsOfService http://swagger.io/terms/
33+
34+
// @contact.name Thirdweb Support
35+
// @contact.url https://thirdweb.com/support
36+
// @contact.email [email protected]
37+
38+
// @license.name Apache 2.0
39+
// @license.url https://github.com/thirdweb-dev/indexer/blob/main/LICENSE
40+
41+
// @host localhost:3000
42+
// @BasePath /
43+
44+
// @securityDefinitions.basic BasicAuth
45+
2446
func RunApi(cmd *cobra.Command, args []string) {
2547
r := gin.New()
2648
r.Use(gin.Logger())
2749
r.Use(gin.Recovery())
2850

51+
// Add Swagger route
52+
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
53+
2954
root := r.Group("/:chainId")
3055
{
3156
root.Use(middleware.Authorization)

0 commit comments

Comments
 (0)