Skip to content

Commit 36211a8

Browse files
authored
Merge pull request #1432 from 0chain/doc/update
Doc/update
2 parents d16854c + e655d47 commit 36211a8

28 files changed

+7349
-317
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,10 @@ else
188188
sed -i "s/BUF_VERSION := [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/BUF_VERSION := $(VERSION)/g" Makefile
189189
endif
190190
endif
191+
192+
.PHONY: markdown-docs
193+
markdown-docs:
194+
swagger generate spec -o ./swagger.yaml -w ./code/go/0chain.net -m
195+
sed -i '' "s/in\:\ form/in\:\ formData/g" ./swagger.yaml
196+
yq -i '(.paths.*.*.parameters.[] | select(.in == "formData") | select(.type == "object")).type = "file"' swagger.yaml
197+
swagger generate markdown -f ./swagger.yaml --output=swagger.md

code/go/0chain.net/blobbercore/allocation/entity.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
CanRenameMask = uint16(32) // 0010 0000
3939
)
4040

41+
// swagger:model Allocation
4142
type Allocation struct {
4243
ID string `gorm:"column:id;size:64;primaryKey"`
4344
Tx string `gorm:"column:tx;size:64;not null;unique;index:idx_unique_allocations_tx,unique"`
@@ -239,6 +240,7 @@ const (
239240
)
240241

241242
// Terms for allocation by its Tx.
243+
// swagger:model
242244
type Terms struct {
243245
ID int64 `gorm:"column:id;primaryKey"`
244246
BlobberID string `gorm:"blobber_id;size:64;not null"`

code/go/0chain.net/blobbercore/allocation/file_changer_base.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/0chain/blobber/code/go/0chain.net/core/encryption"
1212
)
1313

14+
// swagger:model BaseFileChanger
1415
// BaseFileChanger base file change processor
1516
type BaseFileChanger struct {
1617
//client side: unmarshal them from 'updateMeta'/'uploadMeta'

code/go/0chain.net/blobbercore/allocation/file_changer_upload.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/0chain/blobber/code/go/0chain.net/core/common"
1717
)
1818

19+
// swagger:model UploadFileChanger
1920
// UploadFileChanger file change processor for continuous upload in INIT/APPEND/FINALIZE
2021
type UploadFileChanger struct {
2122
BaseFileChanger

code/go/0chain.net/blobbercore/blobberhttp/response.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type ListResult struct {
5555
Entities []map[string]interface{} `json:"list"`
5656
}
5757

58+
// swagger:model DownloadResponse
5859
type DownloadResponse struct {
5960
Success bool `json:"success"`
6061
Data []byte `json:"data"`
@@ -63,6 +64,7 @@ type DownloadResponse struct {
6364
LatestRM *readmarker.ReadMarker `json:"latest_rm"`
6465
}
6566

67+
// swagger:model LatestWriteMarkerResult
6668
type LatestWriteMarkerResult struct {
6769
LatestWM *writemarker.WriteMarker `json:"latest_write_marker"`
6870
PrevWM *writemarker.WriteMarker `json:"prev_write_marker"`

code/go/0chain.net/blobbercore/challenge/timing.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"gorm.io/gorm/clause"
1313
)
1414

15+
// swagger:model ChallengeTiming
1516
type ChallengeTiming struct {
1617
// ChallengeID is the challenge ID generated on blockchain.
1718
ChallengeID string `gorm:"column:challenge_id;size:64;primaryKey" json:"id"`

code/go/0chain.net/blobbercore/filestore/store.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func GetFileStore() FileStorer {
9090
return fileStore
9191
}
9292

93+
// swagger:model FileDownloadResponse
9394
type FileDownloadResponse struct {
9495
Nodes [][][]byte
9596
Indexes [][]int

code/go/0chain.net/blobbercore/handler/auth_ticket.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,29 @@ import (
77
"net/http"
88
)
99

10+
// swagger:model AuthTicketResponse
11+
type AuthTicketResponse struct {
12+
AuthTicket string `json:"auth_ticket"`
13+
}
14+
15+
// swagger:route GET /v1/auth/generate GetAuthTicket
16+
// Generate blobber authentication ticket.
17+
//
18+
// Generate and retrieve blobber authentication ticket signed by the blobber's signature. Used by restricted blobbers to enable users to use them to host allocations.
19+
//
20+
// parameters:
21+
//
22+
// +name: Zbox-Signature
23+
// in: header
24+
// type: string
25+
// description: Digital signature to verify that the sender is 0box service.
26+
// +name: client_id
27+
// type: string
28+
// in: query
29+
// description: Client ID is used as a payload to the token generated. The token represents a signed version of this string by the blobber's private key.
30+
//
31+
// responses:
32+
// 200: AuthTicketResponse
1033
func GenerateAuthTicket(ctx context.Context, r *http.Request) (interface{}, error) {
1134
clientID := r.URL.Query().Get("client_id")
1235
if clientID == "" {
@@ -18,7 +41,7 @@ func GenerateAuthTicket(ctx context.Context, r *http.Request) (interface{}, erro
1841
return nil, common.NewError("signature_failed", "signature failed")
1942
}
2043

21-
return map[string]interface{}{
22-
"auth_ticket": signature,
44+
return &AuthTicketResponse{
45+
AuthTicket: signature,
2346
}, nil
2447
}

code/go/0chain.net/blobbercore/handler/challenge_timings.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,41 @@ import (
88
"strconv"
99
)
1010

11+
// swagger:route GET /challengetimings GetChallengeTimings
12+
// Get challenge timings.
13+
//
14+
// Retrieve challenge timings for the blobber admin.
15+
//
16+
// parameters:
17+
//
18+
// +name: Authorization
19+
// in: header
20+
// type: string
21+
// required: true
22+
// description: Authorization header (Basic auth). MUST be provided to fulfil the request
23+
// +name: from
24+
// in: query
25+
// type: integer
26+
// required: false
27+
// description: An optional timestamp from which to retrieve the challenge timings
28+
// +name: offset
29+
// in: query
30+
// type: integer
31+
// required: false
32+
// description: Pagination offset, start of the page to retrieve. Default is 0.
33+
// +name: limit
34+
// in: query
35+
// type: integer
36+
// required: false
37+
// description: Pagination limit, number of entries in the page to retrieve. Default is 20.
38+
// +name: sort
39+
// in: query
40+
// type: string
41+
// required: false
42+
// description: Direction of sorting based on challenge closure time, either "asc" or "desc". Default is "asc"
43+
//
44+
// responses:
45+
// 200: []ChallengeTiming
1146
func GetChallengeTimings(ctx context.Context, r *http.Request) (interface{}, error) {
1247
var (
1348
fromString = r.URL.Query().Get("from")
@@ -30,6 +65,25 @@ func GetChallengeTimings(ctx context.Context, r *http.Request) (interface{}, err
3065
return challenge.GetChallengeTimings(from, limit)
3166
}
3267

68+
// swagger:route GET /challenge-timings-by-challengeId GetChallengeTimingByChallengeID
69+
// Get challenge timing by challenge ID.
70+
// Retrieve challenge timing for the given challenge ID by the blobber admin.
71+
//
72+
// parameters:
73+
//
74+
// +name: Authorization
75+
// in: header
76+
// type: string
77+
// required: true
78+
// description: Authorization header (Basic auth). MUST be provided to fulfil the request
79+
// +name: challenge_id
80+
// in: query
81+
// type: string
82+
// required: true
83+
// description: Challenge ID for which to retrieve the challenge timing
84+
//
85+
// responses:
86+
// 200: ChallengeTiming
3387
func GetChallengeTiming(ctx context.Context, r *http.Request) (interface{}, error) {
3488
var (
3589
challengeID = r.URL.Query().Get("challenge_id")

0 commit comments

Comments
 (0)