Skip to content

Commit eeed5f0

Browse files
authored
Merge pull request #223 from anywherelan/api-swagger
api: update swagger
2 parents 282cd61 + b6ff832 commit eeed5f0

6 files changed

Lines changed: 345 additions & 194 deletions

File tree

api/debug.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
"github.com/anywherelan/awl/entity"
1717
)
1818

19-
// @Tags Debug
20-
// @Summary Get p2p debug info
21-
// @Produce json
22-
// @Success 200 {object} entity.P2pDebugInfo
23-
// @Router /debug/p2p_info [GET]
19+
// @Tags Debug
20+
// @Summary Get p2p debug info
21+
// @Produce json
22+
// @Success 200 {object} entity.P2pDebugInfo
23+
// @Router /debug/p2p_info [GET]
2424
func (h *Handler) GetP2pDebugInfo(c echo.Context) (err error) {
2525
metricsByProtocol := h.p2p.NetworkStatsByProtocol()
2626
bandwidthByProtocol := make(map[string]entity.BandwidthInfo, len(metricsByProtocol))
@@ -62,13 +62,13 @@ func (h *Handler) GetP2pDebugInfo(c echo.Context) (err error) {
6262
return c.JSONPretty(http.StatusOK, debugInfo, " ")
6363
}
6464

65-
// @Tags Debug
66-
// @Summary Get logs
67-
// @Param logs query int false "Define number of rows of logs to output. On default and 0 prints all."
68-
// @Param from_head query bool false "Print logs from the beginning of logs"
69-
// @Produce plain
70-
// @Success 200 {string} string "log text"
71-
// @Router /debug/log [GET]
65+
// @Tags Debug
66+
// @Summary Get logs
67+
// @Param logs query int false "Define number of rows of logs to output. On default and 0 prints all."
68+
// @Param from_head query bool false "Print logs from the beginning of logs"
69+
// @Produce plain
70+
// @Success 200 {string} string "log text"
71+
// @Router /debug/log [GET]
7272
func (h *Handler) GetLog(c echo.Context) (err error) {
7373
req := entity.LogRequest{}
7474
err = c.Bind(&req)

api/peers.go

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515

1616
const ErrorPeerAliasIsNotUniq = "peer name is not unique"
1717

18-
// @Tags Peers
19-
// @Summary Get known peers info
20-
// @Accept json
21-
// @Produce json
22-
// @Success 200 {array} entity.KnownPeersResponse
23-
// @Router /peers/get_known [GET]
18+
// @Tags Peers
19+
// @Summary Get known peers info
20+
// @Accept json
21+
// @Produce json
22+
// @Success 200 {array} entity.KnownPeersResponse
23+
// @Router /peers/get_known [GET]
2424
func (h *Handler) GetKnownPeers(c echo.Context) (err error) {
2525
result := h.getKnownPeers()
2626
return c.JSON(http.StatusOK, result)
@@ -71,15 +71,15 @@ func (h *Handler) getKnownPeers() []entity.KnownPeersResponse {
7171
return result
7272
}
7373

74-
// @Tags Peers
75-
// @Summary Get known peer settings
76-
// @Accept json
77-
// @Produce json
78-
// @Param body body entity.PeerIDRequest true "Params"
79-
// @Success 200 {object} config.KnownPeer
80-
// @Failure 400 {object} api.Error
81-
// @Failure 404 {object} api.Error
82-
// @Router /peers/get_known_peer_settings [POST]
74+
// @Tags Peers
75+
// @Summary Get known peer settings
76+
// @Accept json
77+
// @Produce json
78+
// @Param body body entity.PeerIDRequest true "Params"
79+
// @Success 200 {object} config.KnownPeer
80+
// @Failure 400 {object} api.Error
81+
// @Failure 404 {object} api.Error
82+
// @Router /peers/get_known_peer_settings [POST]
8383
func (h *Handler) GetKnownPeerSettings(c echo.Context) (err error) {
8484
req := entity.PeerIDRequest{}
8585
err = c.Bind(&req)
@@ -97,15 +97,15 @@ func (h *Handler) GetKnownPeerSettings(c echo.Context) (err error) {
9797
return c.JSON(http.StatusOK, knownPeer)
9898
}
9999

100-
// @Tags Peers
101-
// @Summary Update peer settings
102-
// @Accept json
103-
// @Produce json
104-
// @Param body body entity.UpdatePeerSettingsRequest true "Params"
105-
// @Success 200 "OK"
106-
// @Failure 400 {object} api.Error
107-
// @Failure 404 {object} api.Error
108-
// @Router /peers/update_settings [POST]
100+
// @Tags Peers
101+
// @Summary Update peer settings
102+
// @Accept json
103+
// @Produce json
104+
// @Param body body entity.UpdatePeerSettingsRequest true "Params"
105+
// @Success 200 "OK"
106+
// @Failure 400 {object} api.Error
107+
// @Failure 404 {object} api.Error
108+
// @Router /peers/update_settings [POST]
109109
func (h *Handler) UpdatePeerSettings(c echo.Context) (err error) {
110110
req := entity.UpdatePeerSettingsRequest{}
111111
err = c.Bind(&req)
@@ -151,15 +151,15 @@ func (h *Handler) UpdatePeerSettings(c echo.Context) (err error) {
151151
return c.NoContent(http.StatusOK)
152152
}
153153

154-
// @Tags Peers
155-
// @Summary Invite new peer
156-
// @Accept json
157-
// @Produce json
158-
// @Param body body entity.FriendRequest true "Params"
159-
// @Success 200 "OK"
160-
// @Failure 400 {object} api.Error
161-
// @Failure 500 {object} api.Error
162-
// @Router /peers/invite_peer [POST]
154+
// @Tags Peers
155+
// @Summary Invite new peer
156+
// @Accept json
157+
// @Produce json
158+
// @Param body body entity.FriendRequest true "Params"
159+
// @Success 200 "OK"
160+
// @Failure 400 {object} api.Error
161+
// @Failure 500 {object} api.Error
162+
// @Router /peers/invite_peer [POST]
163163
func (h *Handler) SendFriendRequest(c echo.Context) (err error) {
164164
req := entity.FriendRequest{}
165165
err = c.Bind(&req)
@@ -188,15 +188,15 @@ func (h *Handler) SendFriendRequest(c echo.Context) (err error) {
188188
return c.NoContent(http.StatusOK)
189189
}
190190

191-
// @Tags Peers
192-
// @Summary Accept new peer's invitation
193-
// @Accept json
194-
// @Produce json
195-
// @Param body body entity.FriendRequestReply true "Params"
196-
// @Success 200 "OK"
197-
// @Failure 400 {object} api.Error
198-
// @Failure 500 {object} api.Error
199-
// @Router /peers/accept_peer [POST]
191+
// @Tags Peers
192+
// @Summary Accept new peer's invitation
193+
// @Accept json
194+
// @Produce json
195+
// @Param body body entity.FriendRequestReply true "Params"
196+
// @Success 200 "OK"
197+
// @Failure 400 {object} api.Error
198+
// @Failure 500 {object} api.Error
199+
// @Router /peers/accept_peer [POST]
200200
func (h *Handler) AcceptFriend(c echo.Context) (err error) {
201201
req := entity.FriendRequestReply{}
202202
err = c.Bind(&req)
@@ -236,12 +236,12 @@ func (h *Handler) AcceptFriend(c echo.Context) (err error) {
236236
return c.NoContent(http.StatusOK)
237237
}
238238

239-
// @Tags Peers
240-
// @Summary Get ingoing auth requests
241-
// @Accept json
242-
// @Produce json
243-
// @Success 200 {array} entity.AuthRequest
244-
// @Router /peers/auth_requests [GET]
239+
// @Tags Peers
240+
// @Summary Get ingoing auth requests
241+
// @Accept json
242+
// @Produce json
243+
// @Success 200 {array} entity.AuthRequest
244+
// @Router /peers/auth_requests [GET]
245245
func (h *Handler) GetAuthRequests(c echo.Context) (err error) {
246246
authRequestsMap := h.authStatus.GetIngoingAuthRequests()
247247
authRequests := make([]entity.AuthRequest, 0, len(authRequestsMap))
@@ -271,15 +271,15 @@ func (h *Handler) GetAuthRequests(c echo.Context) (err error) {
271271
return c.JSON(http.StatusOK, authRequests)
272272
}
273273

274-
// @Tags Peers
275-
// @Summary Remove known peer
276-
// @Accept json
277-
// @Produce json
278-
// @Param body body entity.PeerIDRequest true "Params"
279-
// @Success 200 "OK"
280-
// @Failure 400 {object} api.Error
281-
// @Failure 404 {object} api.Error
282-
// @Router /peers/remove [POST]
274+
// @Tags Peers
275+
// @Summary Remove known peer
276+
// @Accept json
277+
// @Produce json
278+
// @Param body body entity.PeerIDRequest true "Params"
279+
// @Success 200 "OK"
280+
// @Failure 400 {object} api.Error
281+
// @Failure 404 {object} api.Error
282+
// @Router /peers/remove [POST]
283283
func (h *Handler) RemovePeer(c echo.Context) (err error) {
284284
req := entity.PeerIDRequest{}
285285
err = c.Bind(&req)
@@ -306,12 +306,12 @@ func (h *Handler) RemovePeer(c echo.Context) (err error) {
306306
return c.NoContent(http.StatusOK)
307307
}
308308

309-
// @Tags Peers
310-
// @Summary Get blocked peers info
311-
// @Accept json
312-
// @Produce json
313-
// @Success 200 {array} config.BlockedPeer
314-
// @Router /peers/get_blocked [GET]
309+
// @Tags Peers
310+
// @Summary Get blocked peers info
311+
// @Accept json
312+
// @Produce json
313+
// @Success 200 {array} config.BlockedPeer
314+
// @Router /peers/get_blocked [GET]
315315
func (h *Handler) GetBlockedPeers(c echo.Context) (err error) {
316316
h.conf.RLock()
317317
result := make([]config.BlockedPeer, 0, len(h.conf.BlockedPeers))

api/settings.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import (
99
"github.com/anywherelan/awl/entity"
1010
)
1111

12-
// @Tags Settings
13-
// @Summary Get my peer info
14-
// @Accept json
15-
// @Produce json
16-
// @Success 200 {object} entity.PeerInfo
17-
// @Router /settings/peer_info [GET]
12+
// @Tags Settings
13+
// @Summary Get my peer info
14+
// @Accept json
15+
// @Produce json
16+
// @Success 200 {object} entity.PeerInfo
17+
// @Router /settings/peer_info [GET]
1818
func (h *Handler) GetMyPeerInfo(c echo.Context) (err error) {
1919
totalBootstraps, connectedBootstraps := h.p2p.BootstrapPeersStats()
2020
netStats := h.p2p.NetworkStats()
@@ -51,13 +51,13 @@ func (h *Handler) GetMyPeerInfo(c echo.Context) (err error) {
5151
return c.JSON(http.StatusOK, peerInfo)
5252
}
5353

54-
// @Tags Settings
55-
// @Summary Update my peer info
56-
// @Accept json
57-
// @Produce json
58-
// @Param body body entity.UpdateMySettingsRequest true "Params"
59-
// @Success 200 "OK"
60-
// @Router /settings/update [POST]
54+
// @Tags Settings
55+
// @Summary Update my peer info
56+
// @Accept json
57+
// @Produce json
58+
// @Param body body entity.UpdateMySettingsRequest true "Params"
59+
// @Success 200 "OK"
60+
// @Router /settings/update [POST]
6161
func (h *Handler) UpdateMySettings(c echo.Context) (err error) {
6262
req := entity.UpdateMySettingsRequest{}
6363
err = c.Bind(&req)
@@ -80,24 +80,24 @@ func (h *Handler) UpdateMySettings(c echo.Context) (err error) {
8080
return c.NoContent(http.StatusOK)
8181
}
8282

83-
// @Tags Settings
84-
// @Summary Export server configuration
85-
// @Accept json
86-
// @Produce json
87-
// @Success 200 {object} config.Config
88-
// @Router /settings/export_server_config [GET]
83+
// @Tags Settings
84+
// @Summary Export server configuration
85+
// @Accept json
86+
// @Produce json
87+
// @Success 200 {object} config.Config
88+
// @Router /settings/export_server_config [GET]
8989
func (h *Handler) ExportServerConfiguration(c echo.Context) (err error) {
9090
data := h.conf.Export()
9191

9292
return c.Blob(http.StatusOK, echo.MIMEApplicationJSON, data)
9393
}
9494

95-
// @Tags Settings
96-
// @Summary List available socks5 proxies
97-
// @Accept json
98-
// @Produce json
99-
// @Success 200 {object} entity.ListAvailableProxiesResponse
100-
// @Router /settings/list_proxies [GET]
95+
// @Tags Settings
96+
// @Summary List available socks5 proxies
97+
// @Accept json
98+
// @Produce json
99+
// @Success 200 {object} entity.ListAvailableProxiesResponse
100+
// @Router /settings/list_proxies [GET]
101101
func (h *Handler) ListAvailableProxies(c echo.Context) (err error) {
102102
proxies := h.socks5.ListAvailableProxies()
103103

@@ -108,13 +108,13 @@ func (h *Handler) ListAvailableProxies(c echo.Context) (err error) {
108108
return c.JSON(http.StatusOK, response)
109109
}
110110

111-
// @Tags Settings
112-
// @Summary Update current proxy settings
113-
// @Accept json
114-
// @Produce json
115-
// @Param body body entity.UpdateProxySettingsRequest true "Params"
116-
// @Success 200 "OK"
117-
// @Router /settings/set_proxy [POST]
111+
// @Tags Settings
112+
// @Summary Update current proxy settings
113+
// @Accept json
114+
// @Produce json
115+
// @Param body body entity.UpdateProxySettingsRequest true "Params"
116+
// @Success 200 "OK"
117+
// @Router /settings/set_proxy [POST]
118118
func (h *Handler) UpdateProxySettings(c echo.Context) (err error) {
119119
req := entity.UpdateProxySettingsRequest{}
120120
err = c.Bind(&req)

application.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ func FrontendStatic() fs.FS {
5555
return fsys
5656
}
5757

58-
// @title Anywherelan API
59-
// @version 0.1
60-
// @description Anywherelan API
58+
// @title Anywherelan API
59+
// @version 0.1
60+
// @description Anywherelan API
6161

62-
// @Host localhost:8639
63-
// @BasePath /api/v0/
62+
// @Host localhost:8639
63+
// @BasePath /api/v0/
6464

65-
//go:generate swag init --parseDependency -g application.go
65+
//go:generate go run github.com/swaggo/swag/cmd/swag@latest init --parseDependency -g application.go
6666
//go:generate rm -f docs/docs.go docs/swagger.json
6767

6868
type Application struct {

0 commit comments

Comments
 (0)