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

#draft feat(rust): added crate with generated with api #257

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
24 changes: 24 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# build and publish rust crate
name: Rust

on:
push:
branches: [ main ]

jobs:
release:
name: Rust
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
override: true
- uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
path: crates/openapi-client
check-repo: true
ignore-unpublished-changes: true
dry-run: true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ dist/
/exports
www/venv
www/.cache

Cargo.lock
target
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[workspace]
members = ["crates/openapi-client"]
24 changes: 24 additions & 0 deletions crates/openapi-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "process-compose-openapi-client"
version = "1.34.0"
edition = "2021"
description = "OpenAPI client for Process Compose"
license = "Apache-2.0"

[dependencies]
progenitor-client = { version = "^0.8.0" }
reqwest = { version = "^0.12", default-features = false, features = [
"json",
"stream",
] }
serde = { version = "^1.0.42", default-features = false, features = ["derive"] }
serde_json = { version = "^1.0.42", default-features = false }

[dev-dependencies]
tokio = { version = "1.4", features = ["macros"] }

[build-dependencies]
progenitor = { version = "0.8.0" }
syn = { version = "2.0.79" }
prettyplease = { version = "0.2.22" }
serde_json = { version = "^1.0.42", default-features = false }
13 changes: 13 additions & 0 deletions crates/openapi-client/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fn main() {
let src = "../../src/docs/swagger.json";
println!("cargo:rerun-if-changed={}", src);
let spec = include_str!("../../src/docs/swagger.json");
let spec = serde_json::from_str(spec).unwrap();
let mut generator = progenitor::Generator::default();
let tokens = generator.generate_tokens(&spec).unwrap();
let ast = syn::parse2(tokens).unwrap();
let content = prettyplease::unparse(&ast);
let mut out_file = std::path::Path::new(&std::env::var("OUT_DIR").unwrap()).to_path_buf();
out_file.push("lib.rs");
std::fs::write(out_file, content).unwrap();
}
1 change: 1 addition & 0 deletions crates/openapi-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include!(concat!(env!("OUT_DIR"), "/lib.rs"));
13 changes: 13 additions & 0 deletions crates/openapi-client/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use process_compose_openapi_client;

#[tokio::test]
async fn compiles_but_errors_with_bad_url() {
let client = process_compose_openapi_client::Client::new("locahost:8080");
match client.get_process_info("process-compose").await {
Ok(response) => {
let _name = &response.name;
unreachable!("errors on bad url");
}
Err(_) => {}
}
}
2 changes: 2 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[toolchain]
channel = "1.81.0"