Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend OpenAPI docs for bus API #1753

Merged
merged 15 commits into from
Dec 18, 2024
19 changes: 18 additions & 1 deletion .changeset/extend_openapi_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ default: major
The following routes were added:
- consensus
- contracts
- contract
- hosts
- host
- metric
- multipart
- objects
- object
- params
- sectors
- settings
- slabbuffers
- slabs
- state
- stats
- syncer
- system
- upload
- txpool
- wallet
- wallet
- webhooks
52 changes: 28 additions & 24 deletions bus/bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,14 +409,15 @@ func (b *Bus) Handler() http.Handler {
"GET /consensus/siafundfee/:payout": b.contractTaxHandlerGET,
"GET /consensus/state": b.consensusStateHandler,

"PUT /contracts": b.contractsHandlerPUT,
"GET /contracts": b.contractsHandlerGET,
"DELETE /contracts/all": b.contractsAllHandlerDELETE,
"POST /contracts/archive": b.contractsArchiveHandlerPOST,
"POST /contracts/form": b.contractsFormHandler,
"GET /contracts/prunable": b.contractsPrunableDataHandlerGET,
"GET /contracts/renewed/:id": b.contractsRenewedIDHandlerGET,
"POST /contracts/spending": b.contractsSpendingHandlerPOST,
"PUT /contracts": b.contractsHandlerPUT,
"GET /contracts": b.contractsHandlerGET,
"DELETE /contracts/all": b.contractsAllHandlerDELETE,
"POST /contracts/archive": b.contractsArchiveHandlerPOST,
"POST /contracts/form": b.contractsFormHandler,
"GET /contracts/prunable": b.contractsPrunableDataHandlerGET,
"GET /contracts/renewed/:id": b.contractsRenewedIDHandlerGET,
"POST /contracts/spending": b.contractsSpendingHandlerPOST,

"GET /contract/:id": b.contractIDHandlerGET,
"DELETE /contract/:id": b.contractIDHandlerDELETE,
"POST /contract/:id/acquire": b.contractAcquireHandlerPOST,
Expand All @@ -431,13 +432,14 @@ func (b *Bus) Handler() http.Handler {
"GET /contract/:id/size": b.contractSizeHandlerGET,
"PUT /contract/:id/usability": b.contractUsabilityHandlerPUT,

"GET /hosts": b.hostsHandlerGET,
"POST /hosts": b.hostsHandlerPOST,
"GET /hosts/allowlist": b.hostsAllowlistHandlerGET,
"PUT /hosts/allowlist": b.hostsAllowlistHandlerPUT,
"GET /hosts/blocklist": b.hostsBlocklistHandlerGET,
"PUT /hosts/blocklist": b.hostsBlocklistHandlerPUT,
"POST /hosts/remove": b.hostsRemoveHandlerPOST,
"GET /hosts": b.hostsHandlerGET,
"POST /hosts": b.hostsHandlerPOST,
"GET /hosts/allowlist": b.hostsAllowlistHandlerGET,
"PUT /hosts/allowlist": b.hostsAllowlistHandlerPUT,
"GET /hosts/blocklist": b.hostsBlocklistHandlerGET,
"PUT /hosts/blocklist": b.hostsBlocklistHandlerPUT,
"POST /hosts/remove": b.hostsRemoveHandlerPOST,

"GET /host/:hostkey": b.hostsPubkeyHandlerGET,
"PUT /host/:hostkey/check": b.hostsCheckHandlerPUT,
"POST /host/:hostkey/resetlostsectors": b.hostsResetLostSectorsPOST,
Expand All @@ -455,22 +457,19 @@ func (b *Bus) Handler() http.Handler {
"POST /multipart/listuploads": b.multipartHandlerListUploadsPOST,
"POST /multipart/listparts": b.multipartHandlerListPartsPOST,

"GET /object/*key": b.objectHandlerGET,
"PUT /object/*key": b.objectHandlerPUT,
"DELETE /object/*key": b.objectHandlerDELETE,
"GET /objects/*prefix": b.objectsHandlerGET,
"POST /objects/copy": b.objectsCopyHandlerPOST,
"POST /objects/remove": b.objectsRemoveHandlerPOST,
"POST /objects/rename": b.objectsRenameHandlerPOST,

"GET /object/*key": b.objectHandlerGET,
"PUT /object/*key": b.objectHandlerPUT,
"DELETE /object/*key": b.objectHandlerDELETE,

"GET /params/gouging": b.paramsHandlerGougingGET,
"GET /params/upload": b.paramsHandlerUploadGET,

"GET /slabbuffers": b.slabbuffersHandlerGET,
"POST /slabbuffer/done": b.packedSlabsHandlerDonePOST,
"POST /slabbuffer/fetch": b.packedSlabsHandlerFetchPOST,

"DELETE /sectors/:hk/:root": b.sectorsHostRootHandlerDELETE,
"DELETE /sectors/:hostkey/:root": b.sectorsHostRootHandlerDELETE,

"GET /settings/gouging": b.settingsGougingHandlerGET,
"PUT /settings/gouging": b.settingsGougingHandlerPUT,
Expand All @@ -481,14 +480,19 @@ func (b *Bus) Handler() http.Handler {
"GET /settings/upload": b.settingsUploadHandlerGET,
"PUT /settings/upload": b.settingsUploadHandlerPUT,

"GET /slabbuffers": b.slabbuffersHandlerGET,
"POST /slabbuffer/done": b.packedSlabsHandlerDonePOST,
"POST /slabbuffer/fetch": b.packedSlabsHandlerFetchPOST,

"POST /slabs/migration": b.slabsMigrationHandlerPOST,
"GET /slabs/partial/:key": b.slabsPartialHandlerGET,
"POST /slabs/partial": b.slabsPartialHandlerPOST,
"POST /slabs/refreshhealth": b.slabsRefreshHealthHandlerPOST,
"GET /slab/:key": b.slabHandlerGET,
"PUT /slab/:key": b.slabHandlerPUT,

"GET /state": b.stateHandlerGET,
"GET /state": b.stateHandlerGET,

"GET /stats/objects": b.objectsStatshandlerGET,

"GET /syncer/address": b.syncerAddrHandler,
Expand Down
27 changes: 15 additions & 12 deletions bus/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ func (b *Bus) settingsS3HandlerPUT(jc jape.Context) {
func (b *Bus) sectorsHostRootHandlerDELETE(jc jape.Context) {
var hk types.PublicKey
var root types.Hash256
if jc.DecodeParam("hk", &hk) != nil {
if jc.DecodeParam("hostkey", &hk) != nil {
return
} else if jc.DecodeParam("root", &root) != nil {
return
Expand Down Expand Up @@ -1584,13 +1584,16 @@ func (b *Bus) slabsRefreshHealthHandlerPOST(jc jape.Context) {

func (b *Bus) slabsMigrationHandlerPOST(jc jape.Context) {
var msr api.MigrationSlabsRequest
if jc.Decode(&msr) == nil {
if slabs, err := b.store.UnhealthySlabs(jc.Request.Context(), msr.HealthCutoff, msr.Limit); jc.Check("couldn't fetch slabs for migration", err) == nil {
jc.Encode(api.UnhealthySlabsResponse{
Slabs: slabs,
})
}
if jc.Decode(&msr) != nil {
return
}

slabs, err := b.store.UnhealthySlabs(jc.Request.Context(), msr.HealthCutoff, msr.Limit)
if jc.Check("couldn't fetch slabs for migration", err) != nil {
return
}

jc.Encode(api.UnhealthySlabsResponse{Slabs: slabs})
}

func (b *Bus) slabsPartialHandlerGET(jc jape.Context) {
Expand Down Expand Up @@ -2018,9 +2021,9 @@ func (b *Bus) webhookHandlerPost(jc jape.Context) {
}

func (b *Bus) metricsHandlerDELETE(jc jape.Context) {
metric := jc.PathParam("key")
if metric == "" {
jc.Error(errors.New("parameter 'metric' is required"), http.StatusBadRequest)
key := jc.PathParam("key")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is even possible considering it's a path param. If key is "", then the path would be different and the router would probably return a 404 before even calling the handler.

if key == "" {
jc.Error(errors.New("unknown metric ''"), http.StatusBadRequest)
return
}

Expand All @@ -2032,7 +2035,7 @@ func (b *Bus) metricsHandlerDELETE(jc jape.Context) {
return
}

err := b.store.PruneMetrics(jc.Request.Context(), metric, cutoff)
err := b.store.PruneMetrics(jc.Request.Context(), key, cutoff)
if jc.Check("failed to prune metrics", err) != nil {
return
}
Expand All @@ -2043,7 +2046,7 @@ func (b *Bus) metricsHandlerPUT(jc jape.Context) {

key := jc.PathParam("key")
if key != api.MetricContractPrune {
jc.Error(fmt.Errorf("unknown metric key '%s'", key), http.StatusBadRequest)
jc.Error(fmt.Errorf("unknown metric '%s'", key), http.StatusBadRequest)
return
}

Expand Down
Loading
Loading