-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[R4R]: add swagger-ui for gaiacli lite-server #2215
[R4R]: add swagger-ui for gaiacli lite-server #2215
Conversation
client/keys/add.go
Outdated
} | ||
|
||
// RecoverResuestHandler is the handler of creating seed in swagger rest server | ||
func RecoverResuestHandler(w http.ResponseWriter, r *http.Request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if you're refering to Rest
or Request
with Resuest
, please change it accordingly
client/keys/add.go
Outdated
decoder := json.NewDecoder(r.Body) | ||
err := decoder.Decode(&m) | ||
if err != nil { | ||
w.WriteHeader(400) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use http
library with the corresponding status codes constants
client/keys/add.go
Outdated
name := vars["name"] | ||
var m RecoverKeyBody | ||
|
||
decoder := json.NewDecoder(r.Body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use wire Codec
to decode the body
client/lcd/README.md
Outdated
``` | ||
go get github.com/rakyll/statik | ||
``` | ||
* Directly Edit API docs: client/lcd/swaggerui/swagger.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add link to file from develop
branch
client/lcd/README.md
Outdated
``` | ||
* Directly Edit API docs: client/lcd/swaggerui/swagger.json | ||
|
||
* Edit API docs within this [website](https://app.swaggerhub.com). Please refer to this [link](https://app.swaggerhub.com/help/index) for how to use the about website to edit API docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
within this [website] [SwaggerHub]
client/lcd/README.md
Outdated
|
||
* Edit API docs within this [website](https://app.swaggerhub.com). Please refer to this [link](https://app.swaggerhub.com/help/index) for how to use the about website to edit API docs. | ||
|
||
* Download swagger.json and replace the old swagger.json under client/lcd/swaggerui folds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Download swagger.json
and replace the old swagger.json
under client/lcd/swaggerui
folder
client/lcd/README.md
Outdated
|
||
* Download swagger.json and replace the old swagger.json under client/lcd/swaggerui folds | ||
|
||
* Regenerate statik.go file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generate a new statik.go
file with the following command:
client/lcd/lcd_test.go
Outdated
// TODO Do we really need this endpoint? | ||
res, body := Request(t, port, "GET", "/keys/seed", nil) | ||
// recover key | ||
recoverKeyURL := fmt.Sprintf("/keys/%s/recover", "test_recover") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move /keys/{name}/recover
logic to a separate function ? Same way as getAccount
, doSend
, etc. are implemented
@@ -18,6 +18,7 @@ import ( | |||
slashingcmd "github.com/cosmos/cosmos-sdk/x/slashing/client/cli" | |||
stakecmd "github.com/cosmos/cosmos-sdk/x/stake/client/cli" | |||
|
|||
_ "github.com/cosmos/cosmos-sdk/client/lcd/statik" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why is this being imported if it's not used ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import will trgger side effects: call the init function of the package. We can also call the init function explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call it explicitly, makes the code more obvious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid that I can't do that.
func init() {
}
The init function is private, so I can't call it explicitly from outside. Besides, this file is generated by statik, so we should avoid to edit it maunally.
client/lcd/README.md
Outdated
* Regenerate statik.go file | ||
``` | ||
statik -src=client/lcd/swaggerui -dest=client/lcd | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens after the new statik.go
file is generated ? Just run gaiacli lite-server
and it's done ? Maybe add that section here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(My question is mainly how do I see the generated docs afterwards)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can start lite-server with this command:
gaiacli lite-server --chain-id=<chain_id>
Then visit the following url with your explorer:
http://localhost:1317/swaggerui/
client/lcd/README.md
Outdated
|
||
## Steps | ||
|
||
* Install the command line tool first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace * for numbers (e.g 1. , 2. , ... ) since they are steps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, I left a couple of comments. Also please make sure to update PENDING.md
since this are breaking changes (specially endpoint renaming).
Also please update Gaia-lite section of the docs with a link to how to update the API (in this case it would be something like https://cosmos.network/docs/sdk/client/lcd/README.html). I remember you already made some comments in that section in one of your other PRs, maybe merge both of them within the Gaia-lite section ?
@HaoyangLiu |
also Golint is failing in CircleCI, make sure that's fixed as well. Thanks ! |
Codecov Report
@@ Coverage Diff @@
## develop #2215 +/- ##
==========================================
- Coverage 61.15% 60.7% -0.45%
==========================================
Files 123 125 +2
Lines 7391 7569 +178
==========================================
+ Hits 4520 4595 +75
- Misses 2558 2660 +102
- Partials 313 314 +1 |
client/keys/add.go
Outdated
// add new key REST handler | ||
func paramCheck(m NewKeyBody, kb keys.Keybase) (int, string) { | ||
if m.Name == "" { | ||
return http.StatusBadRequest, fmt.Sprintf("You have to specify a name for the locally stored account.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for fmt.Sprintf
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to keep the code style consistent. Removing it looks better.
client/keys/add.go
Outdated
return http.StatusBadRequest, fmt.Sprintf("You have to specify a name for the locally stored account.") | ||
} | ||
if m.Password == "" { | ||
return http.StatusBadRequest, fmt.Sprintf("You have to specify a password for the locally stored account.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
@jackzampolin @cwgoes
@fedekunze |
…ing in indent to make response more readable
if there's a simple build process to generate to bunch of files required to serve the RPC docs, the website Makefile can handle this (like it does for the regular docs, it's basically a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requires instructions for building/serving the RPC docs added to docs/DOCS_README.md
docs/light/update_API_docs.md
Outdated
@@ -0,0 +1,18 @@ | |||
# How to update API docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move this whole file to a section in docs/DOCS_README.md
docs/light/update_API_docs.md
Outdated
|
||
1. Install the swagger-ui generate tool first. | ||
``` | ||
make get_tools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which Makefile is this meant to target? should specify that this command is to be run from ... ? (root of repo i think)
@zramsay |
@cwgoes |
@HaoyangLiu The JS files are OK, it's not a big deal. Only remaining issue is investigating why |
@cwgoes |
We've temporarily disabled light client verification in the LCD tests due to an upstream Tendermint issue, so I think you don't need to also do it in This needs to be rebased against develop since the TM 0.24 PR was merged, then we should be good to merge it. |
@cwgoes
Now when executing get status, it will create certifier which require --chain-id. However, certifier should not be created in this command. So I added
|
Excited to see this merged! |
I see, OK - instead, let's use I made a PR - https://github.com/HaoyangLiu/cosmos-sdk/pull/8. |
@cwgoes
Please check the CI failure: https://circleci.com/gh/cosmos/cosmos-sdk/34860#config/containers/0 |
That's strange. I'll try another image in a separate PR (easier to test with PRs against this repo). |
@@ -1,5 +1,6 @@ | |||
package utils | |||
|
|||
import "C" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to have broken cross compilation between Darwin and Linux. Can we safely remove this line or is there any reason why we shouldn't do so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want this cross-compilation ability can we test for it in CI? Then we'll know in the future if we break it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd second the idea, though we have to figure out how go about it - golang/go#19470
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was introduced in #2215, it's presently unnecessary and it is clearly breaking cross compilation.
This is another prototype of swagger-ui implementation for gaia-lite server. Comparing with previous one #2199, this implementation brings in much less code change and easy to maintain.
The following files under
client/lcd/swaggerui
are copied from the swagger-apiBesides,
client/lcd/statik/statik.go
is generated by the tool statik.If we want to update API docs, we just need to follow the steps edit
client/lcd/swaggerui/swagger.json
.Run the following command to start gaia-lite:
Then you can visit this url to check your modified API docs:
@jackzampolin @fedekunze
Do you think this is acceptable? If not please give me some suggestions. Thanks very much.