Skip to content

[RPC] Static swagger#3880

Merged
tac0turtle merged 39 commits intotendermint:masterfrom
sabau:2880-static-swagger
Aug 16, 2019
Merged

[RPC] Static swagger#3880
tac0turtle merged 39 commits intotendermint:masterfrom
sabau:2880-static-swagger

Conversation

@sabau
Copy link
Contributor

@sabau sabau commented Aug 5, 2019

Describing statically the RPC implementation with swagger

Closes: #2880, #2419

The initial goal was to introduce proper annotations:

With both, workarounds to make it work are possible but may create a brittle solution that will soon need to be refactored once go modules are supported (or aliases in the case of swaggo)

The first part of the definitions is organized, the second half is left as it will look once auto-generated, so we can see the differences

  • Referenced an issue explaining the need for the change
  • Updated all relevant documentation in docs
  • Updated all code comments where relevant
  • Wrote tests
  • Updated CHANGELOG_PENDING.md

sabau added 12 commits August 2, 2019 17:54
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
@sabau sabau changed the title 2880 static swagger [RPC] Static swagger Aug 5, 2019
@codecov-io
Copy link

codecov-io commented Aug 5, 2019

Codecov Report

Merging #3880 into master will increase coverage by 1.23%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #3880      +/-   ##
==========================================
+ Coverage   65.65%   66.88%   +1.23%     
==========================================
  Files         217      219       +2     
  Lines       18198    18205       +7     
==========================================
+ Hits        11948    12177     +229     
+ Misses       5382     5139     -243     
- Partials      868      889      +21
Impacted Files Coverage Δ
privval/signer_server.go 95.65% <0%> (-4.35%) ⬇️
consensus/ticker.go 91.66% <0%> (-4.17%) ⬇️
consensus/metrics.go 15.17% <0%> (-1.83%) ⬇️
blockchain/v0/pool.go 80% <0%> (-0.99%) ⬇️
consensus/types/round_state.go
rpc/lib/client/http_client.go
consensus/types/height_vote_set.go
consensus/types/peer_round_state.go
consensus/types/codec.go
rpc/lib/client/ws_client.go
... and 12 more

@safareli
Copy link

safareli commented Aug 6, 2019

This is definition of ResponseInfo message from proto file but it's

message ResponseInfo {
string data = 1;
string version = 2;
uint64 app_version = 3;
int64 last_block_height = 4;
bytes last_block_app_hash = 5;
}

But in swagger file you have:

required:
- "data"
- "last_block_height"
- "last_block_app_hash"

i.e only 3 fields are specified vs 5.

also general issue of having omitempty everywhere in generated types means non of the fileds of generated types are actually required #3882

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
@sabau
Copy link
Contributor Author

sabau commented Aug 8, 2019

Thanks for cathing this @safareli! I will adapt the swagger and double-check what else could have been falling under this category.

@sabau sabau marked this pull request as ready for review August 8, 2019 16:39
@sabau sabau requested review from ebuchman, melekes and xla as code owners August 8, 2019 16:39
@tac0turtle
Copy link
Contributor

@mircea-c can we have this in place of https://tendermint.com/rpc/#introduction, when its merged?

@sabau
Copy link
Contributor Author

sabau commented Aug 9, 2019

@mircea-c @marbar3778 To get this working we should deploy just once the index.html I added in the same folder of the swagger file (if it's an S3 bucket let's just be sure they are both reachable permission-wise) and every time we want to update the RPC docs, just replace swagger.yaml with the new version of it

sabau added 4 commits August 9, 2019 18:43
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
melekes and others added 3 commits August 12, 2019 14:43
That's cleaner, thanks!

Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
sabau added 3 commits August 12, 2019 17:09
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
…lumes

Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
@fadeev
Copy link
Contributor

fadeev commented Aug 12, 2019

@marbar3778 @sabau you guys need to loop in the design team and check how the website is currently set up and what it would take to integrate this into it.

If I understand correctly, to switch to Swagger (from Slate) we would have to edit the Makefile:

https://github.com/tendermint/tendermint.com/blob/master/Makefile#L48

so that it would copy docs/spec/rpc/swagger.yaml and docs/spec/rpc/index.html from this repo into dist/rpc/ in tendermint.com repo. This shouldn't affect the tendermint.com website proper.

sabau added 4 commits August 13, 2019 12:17
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
@sabau
Copy link
Contributor Author

sabau commented Aug 13, 2019

A follow-up PR could make the network a bit more interesting to tests, adding addresses, transactions hashes to look at etc

sabau added 3 commits August 13, 2019 13:57
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Signed-off-by: Karoly Albert Szabo <szabo.karoly.a@gmail.com>
Copy link
Contributor

@thanethomson thanethomson left a comment

Choose a reason for hiding this comment

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

So happy to see contract tests! 🎉 🕺

@@ -0,0 +1,2680 @@
swagger: "2.0"
info:
version: "0.32.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Will we have to manually update the version each time?

description: Evidence APIs
schemes:
- https
host: stargate.cosmos.network:26657
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be using this address here? Due to the more generic nature of Tendermint, I'd imagine we'd need to provide an address that's relevant to a broader user base. The default for Tendermint configuration at the moment is to bind to 127.0.0.1, so should we perhaps not just use:

Suggested change
host: stargate.cosmos.network:26657
host: localhost:26657

Copy link
Contributor

Choose a reason for hiding this comment

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

I do believe this is so when a user comes to the swagger docs they can hit the endpoint and get results back instead of having to spin a local node to be able to test it. similar to the try it out button here: https://cosmos.network/rpc/#/ICS0/get_node_info

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should look into setting up a Tendermint/kvstore node here instead then, running the latest version of Tendermint? Something generic where users can follow along in the Tendermint documentation to interact with the server.

- name: Evidence
description: Evidence APIs
schemes:
- https
Copy link
Contributor

Choose a reason for hiding this comment

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

By default we expose an HTTP interface - could we add that in here?

- "hash"
properties:
code:
type: "string"
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now this is actually an integer. See #3898 - I'm sure we're going to rather tend towards representing all integers as integers instead of strings in future.

Copy link
Contributor

@thanethomson thanethomson Aug 14, 2019

Choose a reason for hiding this comment

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

I've tried adding this comment twice now and GitHub seems to consistently get the line number wrong somehow in the preview 🤷‍♂. Just in case, I'm referring to docs/spec/rpc/swagger.yaml#2666.

contract_tests:
working_directory: /home/circleci/.go_workspace/src/github.com/tendermint/tendermint
machine:
image: circleci/classic:latest
Copy link
Contributor

Choose a reason for hiding this comment

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

why not default one or nodejs?

Copy link
Contributor

Choose a reason for hiding this comment

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

For this @sabau mentioned its either start in node and download go or start in go and download node, he chose node.

Copy link
Contributor

Choose a reason for hiding this comment

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

he chose neither!!

steps:
- checkout
- run:
name: Test RPC endpoints agsainst swagger documentation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name: Test RPC endpoints agsainst swagger documentation
name: Test RPC endpoints against swagger documentation

### RPC Testing

If you contribute to the RPC endpoints it's important to document your changes in the [Swagger file](./docs/spec/rpc/swagger.yaml)
To test your changes you should install `nodejs` version `v11.15.*` and run:
Copy link
Contributor

Choose a reason for hiding this comment

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

don't think we need version here

@tac0turtle tac0turtle mentioned this pull request Aug 16, 2019
6 tasks
Copy link
Contributor

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

⚡️ created follow up an issue for nonaddressed comments, @sabau thank you for your contributions

@tac0turtle tac0turtle merged commit ead3eef into tendermint:master Aug 16, 2019
@safareli
Copy link

When would this be hosted on tendermint website?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Tendermint RPC docs (POST/websocket)

8 participants