Skip to content

Commit

Permalink
Merge PR #5061: Swagger Auto Gen - Staking
Browse files Browse the repository at this point in the history
  • Loading branch information
jackzampolin authored and alexanderbez committed Oct 11, 2019
1 parent 1e204a1 commit 235dc49
Show file tree
Hide file tree
Showing 10 changed files with 4,756 additions and 217 deletions.
1,760 changes: 1,666 additions & 94 deletions client/rest/docs/docs.go

Large diffs are not rendered by default.

1,758 changes: 1,665 additions & 93 deletions client/rest/docs/swagger.json

Large diffs are not rendered by default.

1,090 changes: 1,078 additions & 12 deletions client/rest/docs/swagger.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion x/bank/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// @Param address path string true "Account address to query"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.queryBalance
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid height"
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /bank/balances/{address} [get]
func QueryBalancesRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
Expand Down
2 changes: 1 addition & 1 deletion x/gov/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
// @Param type path string true "Type of param (deposit | tallying | voting)"
// @Param height query string false "Block height (defaults to chain tip)"
// @Success 200 {object} rest.ResponseWithHeight
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid height"
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 404 {object} rest.ErrorResponse "Returned if the type of parameter doesn't exist"
// @Router /gov/parameters/{type} [get]
func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
Expand Down
191 changes: 177 additions & 14 deletions x/staking/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,54 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {

}

// HTTP request handler to query a delegator delegations
// delegatorDelegationsHandlerFn implements a delegator delegations query route
//
// @Summary Query all delegations from a delegator
// @Description Query all delegations from a single delegator address
// @Tags staking
// @Produce json
// @Param delegatorAddr path string true "The delegator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.delegatorDelegations
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/delegators/{delegatorAddr}/delegations [get]
func delegatorDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryDelegator(cliCtx, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegatorDelegations))
}

// HTTP request handler to query a delegator unbonding delegations
// delegatorUnbondingDelegationsHandlerFn implements a delegator unbonding delegations query route
//
// @Summary Query all unbonding delegations from a delegator
// @Description Query all unbonding delegations from a single delegator address
// @Tags staking
// @Produce json
// @Param delegatorAddr path string true "The delegator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.delegatorUnbondingDelegations
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/delegators/{delegatorAddr}/unbonding_delegations [get]
func delegatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryDelegator(cliCtx, "custom/staking/delegatorUnbondingDelegations")
}

// HTTP request handler to query all staking txs (msgs) from a delegator
// delegatorTxsHandlerFn implements a delegator transactions query route
//
// @Summary Query all staking transactions from a delegator
// @Description Query all staking transactions from a single delegator address
// @Description NOTE: In order to query staking transactions, the transaction
// @Description record must be available otherwise the query will fail. This requires a
// @Description node that is not pruning transaction history
// @Tags staking
// @Produce json
// @Param delegatorAddr path string true "The delegator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Param type query string false "Type of staking transaction, either (bond | unbond | redelegate)"
// @Success 200 {object} rest.delegatorTxs
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/delegators/{delegatorAddr}/txs [get]
func delegatorTxsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var typesQuerySlice []string
Expand Down Expand Up @@ -182,12 +219,37 @@ func delegatorTxsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
}

// HTTP request handler to query an unbonding-delegation
// unbondingDelegationHandlerFn implements a delegator/validator unbonding delegations query route
//
// @Summary Query all unbonding delegations from a delegator/validator pair
// @Description Query all unbonding delegations from a single delegator/validator pair
// @Tags staking
// @Produce json
// @Param delegatorAddr path string true "The delegator address"
// @Param validatorAddr path string true "The validator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.unbondingDelegation
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/delegators/{delegatorAddr}/unbonding_delegations/{validatorAddr} [get]
func unbondingDelegationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryBonds(cliCtx, "custom/staking/unbondingDelegation")
}

// HTTP request handler to query redelegations
// redelegationsHandlerFn implements a redelegations query route
//
// @Summary Query all redelegations with filters
// @Description Query all redelegations filtered by delegator, validator_from, and/or validator_to
// @Tags staking
// @Produce json
// @Param delegator query string false "The delegator address"
// @Param validator_from query string false "The source validator address"
// @Param validator_to query string false "The destination validator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.redelegations
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/redelegations [get]
func redelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var params types.QueryRedelegationParams
Expand Down Expand Up @@ -245,22 +307,70 @@ func redelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
}

// HTTP request handler to query a delegation
// delegationHandlerFn implements an individual delegation query route
//
// @Summary Query an individual delegation
// @Description Query an individual delegation
// @Tags staking
// @Produce json
// @Param delegatorAddr path string true "The delegator address"
// @Param validatorAddr path string true "The validator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.delegation
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/delegators/{delegatorAddr}/delegations/{validatorAddr} [get]
func delegationHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryBonds(cliCtx, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryDelegation))
}

// HTTP request handler to query all delegator bonded validators
// delegatorValidatorsHandlerFn implements a delegator's bonded validators query route
//
// @Summary Query a delegator's bonded validators
// @Description Query a delegator's bonded validators
// @Tags staking
// @Produce json
// @Param delegatorAddr path string true "The delegator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.delegatorValidators
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/delegators/{delegatorAddr}/validators [get]
func delegatorValidatorsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryDelegator(cliCtx, "custom/staking/delegatorValidators")
}

// HTTP request handler to get information from a currently bonded validator
// delegatorValidatorHandlerFn implements a delegator's bonded validator query route
//
// @Summary Query a delegator's bonded validator
// @Description Query a delegator's bonded validator
// @Tags staking
// @Produce json
// @Param delegatorAddr path string true "The delegator address"
// @Param validatorAddr path string true "The validator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.delegatorValidator
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/delegators/{delegatorAddr}/validators/{validatorAddr} [get]
func delegatorValidatorHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryBonds(cliCtx, "custom/staking/delegatorValidator")
}

// HTTP request handler to query list of validators
// validatorsHandlerFn implements a validators query route
//
// @Summary Query validators
// @Description Query paginated validators filtering by status
// @Tags staking
// @Produce json
// @Param status query string false "The validator status (bonded | unbonded | unbonding)" default(bonded)
// @Param page query int false "The page number to query" default(1)
// @Param limit query int false "The number of results per page" default(100)
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.validators
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/validators [get]
func validatorsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
Expand Down Expand Up @@ -298,22 +408,65 @@ func validatorsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
}

// HTTP request handler to query the validator information from a given validator address
// validatorHandlerFn implements a validator query route.
//
// @Summary Query a validator
// @Description Query a validator by operator address
// @Tags staking
// @Produce json
// @Param validatorAddr path string true "The validator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.validator
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/validators/{validatorAddr} [get]
func validatorHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryValidator(cliCtx, "custom/staking/validator")
}

// HTTP request handler to query all unbonding delegations from a validator
// validatorDelegationsHandlerFn implements a validator delegations query route.
//
// @Summary Query a validator's delegations
// @Description Query a validator's delegations by operator address
// @Tags staking
// @Produce json
// @Param validatorAddr path string true "The validator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} validatorDelegations
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/validators/{validatorAddr}/delegations [get]
func validatorDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryValidator(cliCtx, fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryValidatorDelegations))
}

// HTTP request handler to query all unbonding delegations from a validator
// validatorUnbondingDelegationsHandlerFn implements a validator unbonding delegations query route
//
// @Summary Query a validator's unbonding delegations
// @Description Query a validator's unbonding delegations by operator address
// @Tags staking
// @Produce json
// @Param validatorAddr path string true "The validator address"
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.validatorUnbondingDelegations
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/validators/{validatorAddr}/unbonding_delegations [get]
func validatorUnbondingDelegationsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return queryValidator(cliCtx, "custom/staking/validatorUnbondingDelegations")
}

// HTTP request handler to query the pool information
// poolHandlerFn implements a staking pool query route
//
// @Summary Query the staking pool
// @Description Query the staking pools
// @Tags staking
// @Produce json
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.pool
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/pool [get]
func poolHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
Expand All @@ -332,7 +485,17 @@ func poolHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
}

// HTTP request handler to query the staking params values
// paramsHandlerFn implements a staking parameters query route.
//
// @Summary Query the staking parameters
// @Description Query the staking parameters
// @Tags staking
// @Produce json
// @Param height query string false "Block height to execute query (defaults to chain tip)"
// @Success 200 {object} rest.params
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have valid query params"
// @Failure 500 {object} rest.ErrorResponse "Returned on server error"
// @Router /staking/parameters [get]
func paramsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
Expand Down
103 changes: 103 additions & 0 deletions x/staking/client/rest/swagger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package rest

import (
sdk "github.com/cosmos/cosmos-sdk/types"
auth "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)

// Concrete Swagger types used to generate REST documentation. Note, these types
// are not actually used but since all queries return a generic JSON raw message,
// they enabled typed documentation.
//
//nolint:deadcode,unused
type (
postDelegation struct {
auth.StdTx
Msgs []types.MsgDelegate `json:"msg"`
}

postRedelegation struct {
auth.StdTx
Msgs []types.MsgBeginRedelegate `json:"msg"`
}

postUndelegate struct {
auth.StdTx
Msgs []types.MsgUndelegate `json:"msg"`
}

delegatorDelegations struct {
Height int64 `json:"height"`
Result []types.DelegationResponse `json:"result"`
}

delegatorUnbondingDelegations struct {
Height int64 `json:"height"`
Result []types.UnbondingDelegation `json:"result"`
}

// XXX: This type won't render correct documentation at the moment due to aliased
// fields.
//
// Ref: https://github.com/swaggo/swag/issues/483
delegatorTxs struct {
Height int64 `json:"height"`
Result []*sdk.SearchTxsResult `json:"result" swaggertype:"array"`
}

delegatorValidators struct {
Height int64 `json:"height"`
Result []types.Validator `json:"result"`
}

delegatorValidator struct {
Height int64 `json:"height"`
Result types.Validator `json:"result"`
}

delegation struct {
Height int64 `json:"height"`
Result types.DelegationResponse `json:"result"`
}

unbondingDelegation struct {
Height int64 `json:"height"`
Result types.UnbondingDelegation `json:"result"`
}

redelegations struct {
Height int64 `json:"height"`
Result types.RedelegationResponses `json:"result"`
}

validators struct {
Height int64 `json:"height"`
Result []types.Validator `json:"result"`
}

validator struct {
Height int64 `json:"height"`
Result types.Validator `json:"result"`
}

validatorDelegations struct {
Height int64 `json:"height"`
Result types.DelegationResponses `json:"result"`
}

validatorUnbondingDelegations struct {
Height int64 `json:"height"`
Result []types.UnbondingDelegation `json:"result"`
}

pool struct {
Height int64 `json:"height"`
Result types.Pool `json:"result"`
}

params struct {
Height int64 `json:"height"`
Result types.Params `json:"result"`
}
)
Loading

0 comments on commit 235dc49

Please sign in to comment.