Skip to content

Commit

Permalink
refactor: remove REST endpoints, openapi-generator-cli can't handle I…
Browse files Browse the repository at this point in the history
…BC swagger
  • Loading branch information
onsails committed Nov 16, 2023
1 parent 71c7959 commit f959937
Show file tree
Hide file tree
Showing 740 changed files with 272 additions and 29,886 deletions.
49 changes: 0 additions & 49 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ serde_json = "1.0.108"
tokio = { version = "1.34.0", features = ["macros"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
haqq-rest = {path = "./rest"}
# haqq-rest = {path = "./rest"}

[workspace]

members = [".", "haqq-build", "rest"]
members = [
".",
"haqq-build",
# "rest"
]

[features]
default = ["proto_full"]
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ This repo contains RPC clients — generated with [buf.build](https://buf.bu

## Rust Client

Rust client is fully functional, supports [gRPC](https://github.com/haqq-network/haqq-clients/blob/master/tests/grpc.rs) and [REST](https://github.com/haqq-network/haqq-clients/blob/master/tests/rest.rs) enpoints.
Rust client is fully functional, supports [gRPC](https://github.com/haqq-network/haqq-clients/blob/master/tests/grpc.rs).

Not published in crates yet but will be any time soon. In order to use, add to your project's `Cargo.toml`:

* `haqq-proto = {git = "https://github.com/haqq-network/haqq-clients"}` — for gRPC endpoints
* `haqq-rest = {git = "https://github.com/haqq-network/haqq-clients"}` — for REST endpoints

**TODO**:

- [ ] REST endpoints (openapi-generator-cli is very buggy for rust)

## TypeScript gRPC-Web Client

Expand Down
18 changes: 9 additions & 9 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ plugins:
- include_file=src/gen/mod.rs
- gen_crate

- plugin: buf.build/grpc-ecosystem/openapiv2:v2.18.1
out: openapi
# https://github.com/grpc-ecosystem/grpc-gateway/blob/main/protoc-gen-openapiv2/main.go
opt:
# - openapi_naming_strategy=simple
- allow_merge=true
# https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.gen.swagger.yaml
- fqn_for_openapi_name=true
- simple_operation_ids=true
# - plugin: buf.build/grpc-ecosystem/openapiv2:v2.18.1
# out: openapi
# # https://github.com/grpc-ecosystem/grpc-gateway/blob/main/protoc-gen-openapiv2/main.go
# opt:
# # - openapi_naming_strategy=simple
# - allow_merge=true
# # https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.gen.swagger.yaml
# - fqn_for_openapi_name=true
# - simple_operation_ids=true

- plugin: buf.build/bufbuild/es:v1.3.1
out: web/gen/proto/connect-web
Expand Down
1 change: 0 additions & 1 deletion buf.work.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ version: v1
directories:
- haqq-node/proto
- cosmos-sdk/proto

85 changes: 57 additions & 28 deletions haqq-build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ fn main() {
std::mem::drop(f);

apply_proto_patches(Path::new(PROTO_GEN_DIR));
apply_openapi_patches(Path::new(OPENAPI_SPEC_GEN_DIR));

let stdout = Stdio::inherit();
let stderr = Stdio::inherit();
Expand All @@ -45,41 +44,71 @@ fn main() {
fs::remove_dir_all(OPENAPI_GEN_DIR).unwrap();
}

let mut cmd = Command::new("openapi-generator-cli");
cmd.args([
"generate",
"-i",
&format!("{}/apidocs.swagger.json", OPENAPI_SPEC_GEN_DIR),
"-g",
"rust",
"-o",
OPENAPI_GEN_DIR,
"--skip-validate-spec",
"--package-name",
"haqq-rest",
]);

cmd.stdout(stdout).stderr(stderr);

let output = cmd.output().unwrap();
assert!(output.status.success());
// let mut cmd = Command::new("openapi-generator-cli");
// cmd.args([
// "generate",
// "-i",
// "haqq-node/client/docs/swagger-ui/swagger.json",
// "-g",
// "rust",
// // "--enum-name-mappings",
// // "Option=Opt,option=opt",
// "-o",
// OPENAPI_GEN_DIR,
// "--skip-validate-spec",
// "--package-name",
// "haqq-rest",
// ]);

// cmd.stdout(stdout).stderr(stderr);

// let output = cmd.output().unwrap();
// assert!(output.status.success());

// apply_rest_patches();
}

// https://github.com/cosmos/cosmos-rust/blob/08353cb090aea4ad1569c5962a1a92d6327cd2d1/proto-build/src/main.rs#L396
fn patch_file(path: impl AsRef<Path>, pattern: &Regex, replacement: &str) -> io::Result<()> {
let mut contents = fs::read_to_string(&path)?;
contents = pattern.replace_all(&contents, replacement).to_string();
fs::write(path, &contents)
fs::write(&path, &contents)
}

fn apply_openapi_patches(openapi_dir: &Path) {
patch_file(
openapi_dir.join("apidocs.swagger.json"),
&Regex::new("version not set").unwrap(),
OPENAPI_VERSION,
)
.expect("error patching apidocs.swagger.json");
}
// fn patch_files(paths: Vec<impl AsRef<Path>>, pattern: &Regex, replacement: &str) -> io::Result<()> {
// for path in paths {
// if let Err(e) = patch_file(path, pattern, replacement) {
// return Err(e);
// }
// }

// Ok(())
// }

// fn apply_rest_patches() {
// for (pattern, replacement) in [
// ("Option<", "core::option::Option<"),
// ("Option::is_", "core::option::Option::is_"),
// ] {
// // FIXME: figure out a way how to rename Option in enum
// // there is --enum-name-mappings option in openapi-generator-cli
// // but apparently it's currently only supported by java generators
// // patch_files(
// // vec![
// // "rest/src/models/cosmos_period_gov_period_v1_period_weighted_vote_option.rs",
// // "rest/src/models/cosmos_period_gov_period_v1beta1_period_vote.rs",
// // "rest/src/models/cosmos_period_gov_period_v1beta1_period_weighted_vote_option.rs",
// // "rest/src/models/gov_v1_votes_200_response_votes_inner_options_inner.rs",
// // "rest/src/models/votes_200_response_votes_inner_options_inner.rs",
// // "rest/src/models/votes_200_response_votes_inner.rs",
// // "rest/src/models/vote_200_response_vote.rs",
// // ],
// // &Regex::new(pattern).unwrap(),
// // replacement,
// // )
// // .expect("error patching rest file");
// }
// }

/// Fix clashing type names in prost-generated code. See cosmos/cosmos-rust#154.
fn apply_proto_patches(proto_dir: &Path) {
Expand Down
2 changes: 1 addition & 1 deletion haqq-node
Submodule haqq-node updated 69 files
+1 −1 .envrc
+1 −0 .gitattributes
+4 −0 .gitignore
+10 −3 Makefile
+0 −1 buf.work.yaml
+0 −162 client/docs/config.json
+5 −3 client/docs/statik/statik.go
+15,108 −0 client/docs/swagger-ui/swagger.json
+10,454 −65,187 client/docs/swagger-ui/swagger.yaml
+6 −7 docker/build.Dockerfile
+3,894 −2,082 docs/package-lock.json
+163 −38 docs/yarn.lock
+216 −7 flake.lock
+13 −14 flake.nix
+14 −12 go.mod
+29 −8 go.sum
+43 −0 nix/devshell.nix
+19 −0 nix/grpc-gateway.nix
+3 −0 package.json
+3 −2 proto/buf.gen.gogo.yaml
+19 −0 proto/buf.gen.swagger.yaml
+12 −7 proto/buf.lock
+5 −3 proto/buf.yaml
+58 −33 proto/ethermint/evm/v1/evm.proto
+4 −3 proto/ethermint/evm/v1/genesis.proto
+26 −12 proto/ethermint/evm/v1/query.proto
+44 −27 proto/ethermint/evm/v1/tx.proto
+16 −7 proto/ethermint/feemarket/v1/feemarket.proto
+1 −1 proto/ethermint/feemarket/v1/genesis.proto
+3 −2 proto/ethermint/feemarket/v1/query.proto
+5 −4 proto/ethermint/feemarket/v1/tx.proto
+7 −4 proto/ethermint/types/v1/account.proto
+8 −4 proto/ethermint/types/v1/dynamic_fee.proto
+8 −6 proto/ethermint/types/v1/web3.proto
+8 −5 proto/evmos/epochs/v1/genesis.proto
+3 −2 proto/evmos/epochs/v1/query.proto
+6 −3 proto/evmos/erc20/v1/erc20.proto
+4 −2 proto/evmos/erc20/v1/events.proto
+8 −6 proto/evmos/erc20/v1/genesis.proto
+5 −4 proto/evmos/erc20/v1/query.proto
+16 −10 proto/evmos/erc20/v1/tx.proto
+7 −7 proto/haqq/coinomics/v1/genesis.proto
+3 −4 proto/haqq/coinomics/v1/query.proto
+2 −1 proto/haqq/vesting/v1/events.proto
+33 −17 proto/haqq/vesting/v1/query.proto
+42 −22 proto/haqq/vesting/v1/tx.proto
+9 −5 proto/haqq/vesting/v1/vesting.proto
+6 −0 scripts/proto-swagger-download-deps.sh
+31 −17 scripts/protoc-swagger-gen.sh
+3 −0 scripts/protocgen.sh
+4 −0 server/config/config.go
+4 −2 types/dynamic_fee.pb.go
+2 −2 types/web3.pb.go
+2 −2 x/epochs/types/genesis.pb.go
+3 −3 x/erc20/types/erc20.pb.go
+4 −2 x/erc20/types/events.pb.go
+5 −3 x/erc20/types/genesis.pb.go
+2 −1 x/erc20/types/query.pb.go
+12 −8 x/erc20/types/tx.pb.go
+20 −11 x/evm/types/evm.pb.go
+8 −4 x/evm/types/query.pb.go
+10 −8 x/evm/types/tx.pb.go
+4 −2 x/feemarket/types/feemarket.pb.go
+6 −4 x/feemarket/types/tx.pb.go
+1 −1 x/vesting/client/cli/query.go
+10 −0 x/vesting/keeper/grpc_query.go
+2 −1 x/vesting/types/events.pb.go
+12 −6 x/vesting/types/query.pb.go
+16 −9 x/vesting/types/tx.pb.go
3 changes: 0 additions & 3 deletions rest/.gitignore

This file was deleted.

23 changes: 0 additions & 23 deletions rest/.openapi-generator-ignore

This file was deleted.

Loading

0 comments on commit f959937

Please sign in to comment.