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

Swagger Auto Gen - Gov Updates #5088

Merged
merged 11 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@ jobs:
name: upload
command: bash <(curl -s https://codecov.io/bash) -f coverage.txt

update-swagger-docs:
verify-swagger-docs:
executor: golang
steps:
- make:
target: update-swagger-docs
description: "Check if Swagger docs are up-to-date"
target: verify-swagger-docs
description: "Verify Swagger docs are up-to-date"

workflows:
version: 2
test-suite:
jobs:
- update-swagger-docs:
- verify-swagger-docs:
requires:
- setup-dependencies
- setup-dependencies:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ build: go.sum
.PHONY: build

update-swagger-docs: swag
@scripts/swag.sh $(BINDIR)/swag
$(BINDIR)/swag init -g client/rest/root.go --output client/rest/docs
.PHONY: update-swagger-docs

verify-swagger-docs: swag
@scripts/swag.sh $(BINDIR)/swag
.PHONY: verify-swagger-docs

mocks: $(MOCKS_DIR)
mockgen -source=x/auth/types/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go
.PHONY: mocks
Expand Down
28 changes: 14 additions & 14 deletions x/gov/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
//
// @Summary Query governance parameters
// @Tags governance
// @Description Query either (deposit | tallying | voting) parameters of the governance module.
// @Description Query either (deposit | tallying | voting) parameters of the governance module
// @Produce json
// @Param type path string true "Type of param (deposit | tallying | voting)"
// @Param height query string false "Block height (defaults to chain tip)"
Expand Down Expand Up @@ -69,7 +69,7 @@ func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// @Produce json
// @Param proposalID path int true "The ID of the governance proposal"
// @Param height query string false "Block height (defaults to chain tip)"
// @Success 200 {object} rest.ResponseWithHeight
// @Success 200 {object} rest.queryProposal
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid proposal ID or height"
// @Failure 500 {object} rest.ErrorResponse "Returned if the store query fails"
// @Router /gov/proposals/{proposalID} [get]
Expand Down Expand Up @@ -121,11 +121,11 @@ func queryProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// @Description Query an individual governance proposal's deposits.
// @Description NOTE: In order to query deposits for passed proposals, the transaction
// @Description record must be available otherwise the query will fail. This requires a
// @Description node that is not pruning transaction history.
// @Description node that is not pruning transaction history
// @Produce json
// @Param proposalID path int true "The ID of the governance proposal"
// @Param height query string false "Block height (defaults to chain tip)"
// @Success 200 {object} rest.ResponseWithHeight
// @Success 200 {object} rest.queryDeposits
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid proposal ID or height"
// @Failure 500 {object} rest.ErrorResponse "Returned if the store query fails"
// @Router /gov/proposals/{proposalID}/deposits [get]
Expand Down Expand Up @@ -191,7 +191,7 @@ func queryDepositsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// @Produce json
// @Param proposalID path int true "The ID of the governance proposal"
// @Param height query string false "Block height (defaults to chain tip)"
// @Success 200 {object} rest.ResponseWithHeight
// @Success 200 {object} rest.queryProposer
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid proposal ID or height"
// @Failure 500 {object} rest.ErrorResponse "Returned if the store query fails"
// @Router /gov/proposals/{proposalID}/proposer [get]
Expand Down Expand Up @@ -221,19 +221,19 @@ func queryProposerHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}

// queryDepositHandlerFn implements a governance proposal deposit querying route
// for returning data on a governance proposal's individual deposits.
// for returning data on a governance proposal's individual deposits
//
// @Summary Query a governance proposal's individual deposit
// @Tags governance
// @Description Query an individual governance proposal's deposits.
// @Description NOTE: In order to query a deposit for a passed proposal, the transaction
// @Description record must be available otherwise the query will fail. This requires a
// @Description node that is not pruning transaction history.
// @Description node that is not pruning transaction history
// @Produce json
// @Param proposalID path int true "The ID of the governance proposal"
// @Param depositor path string true "The address of the depositor"
// @Param height query string false "Block height (defaults to chain tip)"
// @Success 200 {object} rest.ResponseWithHeight
// @Success 200 {object} rest.queryDeposit
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid proposalID or depositor"
// @Failure 404 {object} rest.ErrorResponse "Returned if the proposal is not found"
// @Failure 500 {object} rest.ErrorResponse "Returned if the store query fails"
Expand Down Expand Up @@ -328,12 +328,12 @@ func queryDepositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// @Description Query an individual governance proposal's vote.
// @Description NOTE: In order to query votes for passed proposals, the transaction
// @Description record must be available otherwise the query will fail. This requires a
// @Description node that is not pruning transaction history.
// @Description node that is not pruning transaction history
// @Produce json
// @Param proposalID path int true "The ID of the governance proposal"
// @Param voter path string true "The address of the voter"
// @Param height query string false "Block height (defaults to chain tip)"
// @Success 200 {object} rest.ResponseWithHeight
// @Success 200 {object} rest.queryVote
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid proposal ID or voter address"
// @Failure 404 {object} rest.ErrorResponse "Returned if the proposal is not found"
// @Failure 500 {object} rest.ErrorResponse "Returned if the store query fails"
Expand Down Expand Up @@ -430,11 +430,11 @@ func queryVoteHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// @Description Query an individual governance proposal's votes.
// @Description NOTE: In order to query deposits for passed proposals, the transaction
// @Description record must be available otherwise the query will fail. This requires a
// @Description node that is not pruning transaction history.
// @Description node that is not pruning transaction history
// @Produce json
// @Param proposalID path int true "The ID of the governance proposal"
// @Param height query string false "Block height (defaults to chain tip)"
// @Success 200 {object} rest.ResponseWithHeight
// @Success 200 {object} rest.queryVotesOnProposal
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid proposal ID or height"
// @Failure 500 {object} rest.ErrorResponse "Returned if the store query fails"
// @Router /gov/proposals/{proposalID}/votes [get]
Expand Down Expand Up @@ -511,7 +511,7 @@ func queryVotesOnProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// @Param status query string false "Filter proposals by proposal status (deposit_period | voting_period | passed | rejected)"
// @Param depositor query string false "Filter proposals by depositor address"
// @Param voter query string false "Filter proposals by voter address"
// @Success 200 {object} rest.ResponseWithHeight
// @Success 200 {object} rest.queryProposals
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid parameters"
// @Failure 500 {object} rest.ErrorResponse "Returned if the store query fails"
// @Router /gov/proposals [get]
Expand Down Expand Up @@ -591,7 +591,7 @@ func queryProposalsWithParameterFn(cliCtx context.CLIContext) http.HandlerFunc {
// @Produce json
// @Param proposalID path int true "The ID of the governance proposal"
// @Param height query string false "Block height (defaults to chain tip)"
// @Success 200 {object} rest.ResponseWithHeight
// @Success 200 {object} rest.queryTally
// @Failure 400 {object} rest.ErrorResponse "Returned if the request doesn't have a valid proposal ID or height"
// @Failure 500 {object} rest.ErrorResponse "Returned if the store query fails"
// @Router /gov/proposals/{proposalID}/tally [get]
Expand Down
53 changes: 53 additions & 0 deletions x/gov/client/rest/swagger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package rest

import (
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
"github.com/cosmos/cosmos-sdk/x/gov/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
type (
queryDeposits struct {
Height int64 `json:"height"`
Result []types.Deposit `json:"result"`
}

queryProposal struct {
Height int64 `json:"height"`
Result types.Proposal `json:"result"`
}

queryProposer struct {
Height int64 `json:"height"`
Result gcutils.Proposer `json:"result"`
}

queryDeposit struct {
Height int64 `json:"height"`
Result types.Deposit `json:"result"`
}

queryVote struct {
Height int64 `json:"height"`
Result types.Vote `json:"result"`
}

queryVotesOnProposal struct {
Height int64 `json:"height"`
Result types.Votes `json:"result"`
}

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

queryTally struct {
Height int64 `json:"height"`
Result types.TallyResult `json:"result"`
}
)
39 changes: 32 additions & 7 deletions x/gov/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/rest"
auth "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/auth/client/utils"
gcutils "github.com/cosmos/cosmos-sdk/x/gov/client/utils"
"github.com/cosmos/cosmos-sdk/x/gov/types"
Expand All @@ -25,16 +26,24 @@ func registerTxRoutes(cliCtx context.CLIContext, r *mux.Router, phs []ProposalRE
r.HandleFunc(fmt.Sprintf("/gov/proposals/{%s}/votes", RestProposalID), voteHandlerFn(cliCtx)).Methods("POST")
}

// postProposal is used to generate documentation for postProposalHandlerFn
type postProposal struct {
Msgs []types.MsgSubmitProposal `json:"msg" yaml:"msg"`
Fee auth.StdFee `json:"fee" yaml:"fee"`
Signatures []auth.StdSignature `json:"signatures" yaml:"signatures"`
Memo string `json:"memo" yaml:"memo"`
}

// postProposalHandlerFn implements a proposal generation handler that
// is responsible for constructing a properly formatted proposal for signing.
//
// @Summary Generate an unsigned proposal transaction
// @Description Generate a proposal transaction that is ready for signing.
// @Description Generate a proposal transaction that is ready for signing
// @Tags governance
// @Accept json
// @Produce json
// @Param tx body rest.PostProposalReq true "The data required to construct a proposal message. The proposal_type can be text | parameter_change"
// @Success 200 {object} types.StdTx
// @Param body body rest.PostProposalReq true "The data required to construct a proposal message, the proposal_type can be (text | parameter_change)"
// @Success 200 {object} postProposal
// @Failure 400 {object} rest.ErrorResponse "Returned if the request is invalid"
// @Router /gov/proposals [post]
func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
Expand Down Expand Up @@ -62,6 +71,14 @@ func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
}

// postDeposit is used to generate documentation for postDepositHandlerFn
type postDeposit struct {
Msgs []types.MsgDeposit `json:"msg" yaml:"msg"`
Fee auth.StdFee `json:"fee" yaml:"fee"`
Signatures []auth.StdSignature `json:"signatures" yaml:"signatures"`
Memo string `json:"memo" yaml:"memo"`
}

// depositHandlerFn implements a deposit generation handler that
// is responsible for constructing a properly formatted deposit for signing.
//
Expand All @@ -71,8 +88,8 @@ func postProposalHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// @Accept json
// @Produce json
// @Param proposalID path int true "The ID of the governance proposal to deposit to"
// @Param tx body rest.DepositReq true "The data required to construct a deposit message"
// @Success 200 {object} types.StdTx
// @Param body body rest.DepositReq true "The data required to construct a deposit message"
// @Success 200 {object} postDeposit
// @Failure 400 {object} rest.ErrorResponse "Returned if the request is invalid"
// @Router /gov/proposals/{proposalID}/deposits [post]
func depositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
Expand Down Expand Up @@ -111,6 +128,14 @@ func depositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}
}

// postVote is used to generate documentation for postVoteHandlerFn
type postVote struct {
Msgs []types.MsgVote `json:"msg" yaml:"msg"`
Fee auth.StdFee `json:"fee" yaml:"fee"`
Signatures []auth.StdSignature `json:"signatures" yaml:"signatures"`
Memo string `json:"memo" yaml:"memo"`
}

// voteHandlerFn implements a governance vote generation handler that
// is responsible for constructing a properly formatted governance vote for signing.
//
Expand All @@ -120,8 +145,8 @@ func depositHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
// @Accept json
// @Produce json
// @Param proposalID path int true "The ID of the governance proposal to vote for"
// @Param tx body rest.VoteReq true "The data required to construct a vote message"
// @Success 200 {object} types.StdTx
// @Param body body rest.VoteReq true "The data required to construct a vote message"
// @Success 200 {object} postVote
// @Failure 400 {object} rest.ErrorResponse "Returned if the request is invalid"
// @Router /gov/proposals/{proposalID}/votes [post]
func voteHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
Expand Down