Skip to content

Commit

Permalink
Init open-api with an example. (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
silathdiir authored Aug 26, 2021
1 parent afdacdf commit 0d27078
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
133 changes: 133 additions & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ log = "0.4.14"
nix = "0.20.0"
num_enum = "0.5.1"
orchestra = { git = "https://github.com/fluidex/orchestra.git", branch = "master", features = [ "exchange" ] }
paperclip = { git = "https://github.com/fluidex/paperclip.git", features = ["actix"] }
qstring = "0.7.2"
rand = "0.8.3"
serde = { version = "1.0.124", features = [ "derive" ] }
Expand All @@ -42,6 +43,10 @@ tracing-appender = "0.1"
tracing-subscriber = "0.2"
ttl_cache = "0.5.1"

[[bin]]
name = "openapi"
path = "src/bin/openapi.rs"

[[bin]]
name = "restapi"
path = "src/bin/restapi.rs"
Expand Down
32 changes: 32 additions & 0 deletions src/bin/openapi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use actix_web::{App, HttpServer};
use paperclip::actix::{
api_v2_operation,
web::{self, Json},
Apiv2Schema, OpenApiExt,
};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Apiv2Schema)]
struct Pet {
name: String,
id: Option<i64>,
}

#[api_v2_operation]
async fn echo_pet(body: Json<Pet>) -> Result<Json<Pet>, actix_web::Error> {
Ok(body)
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.wrap_api()
.service(web::resource("/pets").route(web::post().to(echo_pet)))
.with_json_spec_at("/api/spec")
.build()
})
.bind("0.0.0.0:50054")?
.run()
.await
}

0 comments on commit 0d27078

Please sign in to comment.