Skip to content

Commit b472d3c

Browse files
author
Amine Afia
committed
Integrate swagger docs
1 parent de8ab92 commit b472d3c

File tree

9 files changed

+2765
-23
lines changed

9 files changed

+2765
-23
lines changed

api/api.go

Lines changed: 44 additions & 16 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 {
17-
Code int `json:"code"`
18-
Message string `json:"message"`
19+
// @Description HTTP status code
20+
Code int `json:"code"`
21+
// @Description Error message
22+
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:"-"`
24-
GroupBy string `schema:"group_by"`
25-
SortBy string `schema:"sort_by"`
26-
SortOrder string `schema:"sort_order"`
27-
Page int `schema:"page"`
28-
Limit int `schema:"limit"`
29-
Aggregates []string `schema:"aggregate"`
32+
// @Description Field to group results by
33+
GroupBy string `schema:"group_by"`
34+
// @Description Field to sort results by
35+
SortBy string `schema:"sort_by"`
36+
// @Description Sort order (asc or desc)
37+
SortOrder string `schema:"sort_order"`
38+
// @Description Page number for pagination
39+
Page int `schema:"page"`
40+
// @Description Number of items per page
41+
Limit int `schema:"limit"`
42+
// @Description List of aggregate functions to apply
43+
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 {
33-
ChainId uint64 `json:"chain_id"`
49+
// @Description Chain ID of the blockchain
50+
ChainId uint64 `json:"chain_id"`
51+
// @Description Contract address
3452
ContractAddress string `json:"address"`
35-
Signature string `json:"signature"`
36-
Page int `json:"page"`
37-
Limit int `json:"limit"`
38-
TotalItems int `json:"total_items"`
39-
TotalPages int `json:"total_pages"`
53+
// @Description Function or event signature
54+
Signature string `json:"signature"`
55+
// @Description Current page number
56+
Page int `json:"page"`
57+
// @Description Number of items per page
58+
Limit int `json:"limit"`
59+
// @Description Total number of items
60+
TotalItems int `json:"total_items"`
61+
// @Description Total number of pages
62+
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 {
43-
Meta Meta `json:"meta"`
44-
Data interface{} `json:"data,omitempty"`
68+
// @Description Metadata for the query response
69+
Meta Meta `json:"meta"`
70+
// @Description Query result data
71+
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 v0.0.1-beta
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)