forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
47 lines (40 loc) · 1.24 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
Package swagger provides Swagger UI support for server/v2.
Example usage:
import (
"cosmossdk.io/client/docs"
"cosmossdk.io/core/server"
"cosmossdk.io/log"
swaggerv2 "cosmossdk.io/server/v2/api/swagger"
)
// Create a logger
logger := log.NewLogger()
// Configure Swagger server
swaggerCfg := server.ConfigMap{
"swagger": map[string]any{
"enable": true,
"address": "localhost:8080",
"path": "/swagger/",
},
}
// Create new Swagger server with the default SDK Swagger UI
swaggerServer, err := swaggerv2.New[YourTxType](
logger.With(log.ModuleKey, "swagger"),
swaggerCfg,
swaggerv2.CfgOption(func(cfg *swaggerv2.Config) {
cfg.SwaggerUI = docs.SwaggerUI // Use the default SDK Swagger UI
}),
)
if err != nil {
// Handle error
}
// Add Swagger server to your application
app.AddServer(swaggerServer)
The server will serve Swagger UI documentation at the configured path (default: /swagger/).
Users can customize the configuration through the following options:
- enable: Enable/disable the Swagger server
- address: The address to listen on (default: localhost:8080)
- path: The path to serve Swagger UI at (default: /swagger/)
- SwaggerUI: The http.FileSystem containing Swagger UI files
*/
package swagger