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

Synchronize with the Rocket v0.5-rc branch #4

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"okapi",
"rocket-okapi",
"rocket-okapi-codegen",
"rocket-okapi-ui",
"examples/json-web-api",
"examples/secure_request_guard"
]
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ only change your usage in Cargo toml to something like this by adding the "packa
```toml
okapi = { version = "0.x.x", features = ["derive_json_schema"], package = "okapi_fork" }
rocket_okapi = { version = "0.x.x", package = "rocket_okapi_fork" }

rocket_okapi_ui = "0.x.x"
```

Work in progress!
Expand All @@ -18,9 +18,11 @@ Work in progress!
extern crate rocket;
#[macro_use]
extern crate rocket_okapi;
#[macro_use]
extern crate rocket_okapi_ui;

use rocket_contrib::json::Json;
use rocket_okapi::swagger_ui::make_swagger_ui;
use rocket_okapi_ui::*;
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;

Expand Down Expand Up @@ -59,20 +61,26 @@ fn hidden() -> Json<&'static str> {
Json("Hidden from swagger!")
}

pub fn make_rocket() -> rocket::Rocket {
#[launch]
fn rocket() -> _ {
// You can optionally host Swagger UI
// To do this, create a config to attach it later
let swagger_config = SwaggerUIConfig {
url: "../openapi.json".to_owned(),
..Default::default()
};

rocket::build()
// routes_with_openapi![...] will host the openapi document at openapi.json
.mount(
"/",
routes_with_openapi![get_user, hidden],
)
// You can optionally host swagger-ui too
// Attach the Swagger UI config and mount the routes
.attach(swagger_config.fairing())
.mount(
"/swagger-ui/",
make_swagger_ui(&SwaggerUIConfig {
url: "../openapi.json".to_owned(),
..Default::default()
}),
swagger_ui_routes![],
)
}
```
Expand Down
13 changes: 10 additions & 3 deletions examples/json-web-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ authors = ["Graham Esau <[email protected]>"]
edition = "2018"

[dependencies]
rocket = { version = "0.5.0-rc.1", default-features = false, features = ["json"] }
schemars = { version = "0.8" } #, features = ["preserve_order"] }
okapi = { version = "0.6.0-alpha-1", path = "../../okapi", package = "okapi_fork" }
rocket_okapi = { version = "0.7.0-alpha-1", path = "../../rocket-okapi", package = "rocket_okapi_fork" }
okapi = { version = "0.6.1", path = "../../okapi", package = "okapi_fork" }
rocket_okapi = { version = "0.8.0-rc.1", path = "../../rocket-okapi", package = "rocket_okapi_fork" }
rocket_okapi_ui = { version = "0.1.0-rc.1", path = "../../rocket-okapi-ui" }
serde = "1.0"

[dependencies.rocket]
git = "https://github.com/SergioBenitez/Rocket"
branch = "v0.5-rc"
version = "0.5.0-rc.1"
default-features = false
features = ["json"]
24 changes: 13 additions & 11 deletions examples/json-web-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
extern crate rocket;
#[macro_use]
extern crate rocket_okapi;
#[macro_use]
extern crate rocket_okapi_ui;

use rocket::form::FromForm;
use rocket::serde::json::Json;
use rocket_okapi::swagger_ui::*;
use rocket_okapi_ui::*;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -93,9 +95,15 @@ fn create_post_by_query(post: Post) -> Option<Json<Post>> {
Some(Json(post))
}

#[rocket::main]
async fn main() {
let result = rocket::build()
#[rocket::launch]
fn rocket() -> _ {
let swagger_ui_config = SwaggerUIConfig {
url: "../openapi.json".to_owned(),
..Default::default()
};

rocket::build()
.attach(swagger_ui_config.fairing())
.mount(
"/",
routes_with_openapi![
Expand All @@ -109,12 +117,6 @@ async fn main() {
)
.mount(
"/swagger-ui/",
make_swagger_ui(&SwaggerUIConfig {
url: "../openapi.json".to_owned(),
..SwaggerUIConfig::default()
}),
swagger_ui_routes![],
)
.launch()
.await;
assert!(result.is_ok());
}
15 changes: 10 additions & 5 deletions examples/secure_request_guard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ authors = ["Kristoffer Ödmark <[email protected]>"]
edition = "2018"

[dependencies]
rocket = { version = "0.5.0-rc.1", default-features = false, features = ["json"] }
schemars = { version = "0.8"}
okapi= { version = "0.6.0-alpha-1", path = "../../okapi" , package = "okapi_fork"}
rocket_okapi= { version = "0.7.0-alpha-1", path = "../../rocket-okapi", package = "rocket_okapi_fork"}
serde = "1.0"
tokio = "1.6"
okapi = { version = "0.6.1", path = "../../okapi", package = "okapi_fork"}
rocket_okapi = { version = "0.8.0-rc.1", path = "../../rocket-okapi", package = "rocket_okapi_fork"}
rocket_okapi_ui = { version = "0.1.0-rc.1", path = "../../rocket-okapi-ui" }

[dependencies.rocket]
git = "https://github.com/SergioBenitez/Rocket"
branch = "v0.5-rc"
version = "0.5.0-rc.1"
default-features = false
features = ["json"]
20 changes: 10 additions & 10 deletions examples/secure_request_guard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use rocket_okapi::{
request::{OpenApiFromRequest, RequestHeaderInput},
response::OpenApiResponder,
routes_with_openapi,
swagger_ui::{make_swagger_ui, SwaggerUIConfig},
};
use rocket_okapi_ui::{SwaggerUIConfig, swagger_ui_routes};

pub struct KeyAuthorize;

Expand Down Expand Up @@ -106,19 +106,19 @@ pub fn restricted(_key: KeyAuthorize) -> Json<String> {
Json("You got access here, hurray".into())
}

#[tokio::main]
async fn main() {
#[rocket::launch]
fn rocket() -> _ {
let rocket_config = Config::debug_default();
let swagger_config = SwaggerUIConfig {
url: "/openapi.json".to_string(),
..Default::default()
};

let e = rocket::custom(rocket_config)
rocket::custom(rocket_config)
.attach(swagger_config.fairing())
.mount("/", routes_with_openapi![restricted])
.mount(
"/api/",
make_swagger_ui(&SwaggerUIConfig {
url: "/openapi.json".to_string(),
..Default::default()
}),
swagger_ui_routes![],
)
.launch()
.await;
}
3 changes: 2 additions & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ sleep 20
cargo release --manifest-path rocket-okapi-codegen/Cargo.toml --skip-tag --skip-push $@
sleep 20
cargo release --manifest-path rocket-okapi/Cargo.toml --skip-tag --skip-push $@

sleep 20
cargo release --manifest-path rocket-okapi-ui/Cargo.toml --skip-tag --skip-push $@
4 changes: 4 additions & 0 deletions rocket-okapi-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target
**/*.rs.bk
Cargo.lock
/.idea
23 changes: 23 additions & 0 deletions rocket-okapi-ui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[package]
name = "rocket_okapi_ui"
description = "Crate for embedding Swagger Web UI into Rocket applications"
version = "0.1.0-rc.1"
repository = "https://github.com/TotalKrill/okapi"
authors = [
"Graham Esau <[email protected]>",
"Kristoffer Ödmark <[email protected]>",
"Petr Tsymbarovich <[email protected]>"
]
edition = "2018"
license = "MIT"
keywords = ["rust", "openapi", "swagger", "rocket"]

[dependencies]
serde = "1.0"

[dependencies.rocket]
git = "https://github.com/SergioBenitez/Rocket"
branch = "v0.5-rc"
version = "0.5.0-rc.1"
default-features = false
features = ["json"]
Loading