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

Implement swagger docs and fix path validation #434

Merged
merged 7 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@ build-wasmd:
delete-chains:
@echo "Removing the ./chain-code/ directory..."
@rm -rf ./chain-code

check-swagger:
which swagger || (GO111MODULE=off go get -u github.com/go-swagger/go-swagger/cmd/swagger)

update-swagger-docs: check-swagger
swagger generate spec -o ./docs/swagger-ui/swagger.yaml

6 changes: 5 additions & 1 deletion cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ func getAPICmd() *cobra.Command {
// Data for this should be stored in the ServicesManager struct
r.HandleFunc("/listen/{path}/{strategy}/{name}", PostRelayerListenHandler(sm)).Methods("POST")

fs := http.FileServer(http.Dir("./docs/swagger-ui"))
r.PathPrefix("/").Handler(fs)

fmt.Println("listening on", config.Global.APIListenPort)

if err := http.ListenAndServe(config.Global.APIListenPort, r); err != nil {
return err
}

fmt.Println("listening on", config.Global.APIListenPort)
return nil
},
}
Expand Down
11 changes: 9 additions & 2 deletions cmd/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,10 @@ type addChainRequest struct {
GasAdjustment string `json:"gas-adjustment"`
GasPrices string `json:"gas-prices"`
TrustingPeriod string `json:"trusting-period"`
FilePath string `json:"file"`
URL string `json:"url"`
// required: false
FilePath string `json:"file"`
// required: false
URL string `json:"url"`
}

// PostChainHandler handles the route
Expand Down Expand Up @@ -678,6 +680,11 @@ func PutChainHandler(w http.ResponseWriter, r *http.Request) {
// DeleteChainHandler handles the route
func DeleteChainHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
_, err := config.Chains.Get(vars["name"])
if err != nil {
helpers.WriteErrorResponse(http.StatusBadRequest, err, w)
return
}
if err := overWriteConfig(config.DeleteChain(vars["name"])); err != nil {
helpers.WriteErrorResponse(http.StatusInternalServerError, err, w)
return
Expand Down
9 changes: 5 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,16 @@ func (c *Config) ValidatePathEnd(pe *relayer.PathEnd) error {
return err
}

chain, err := c.Chains.Get(pe.ChainID)
if err != nil {
return err
}

// if the identifiers are empty, don't do any validation
if pe.ClientID == "" && pe.ConnectionID == "" && pe.ChannelID == "" {
return nil
}

chain, err := c.Chains.Get(pe.ChainID)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
// NOTE: this is just to do validation, the path
// is not written to the config file
if err = chain.SetPath(pe); err != nil {
Expand Down
Loading