Skip to content

Commit

Permalink
Support for rocket v0.5.0 (#132)
Browse files Browse the repository at this point in the history
* support for rocket v0.5.0
* update rocket version in README
  • Loading branch information
West14 committed Nov 21, 2023
1 parent 345e117 commit df597f0
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ visualize the documentation. Rocket-okapi currently includes [RapiDoc][RapiDoc]
[Swagger UI][Swagger_UI], but others can be used too.

Supported OpenAPI Spec: [3.0.0][OpenAPI_3.0.0]<br/>
Supported Rocket version (for `rocket_okapi`): [0.5.0-rc.2](https://crates.io/crates/rocket/0.5.0-rc.2)
Supported Rocket version (for `rocket_okapi`): [0.5.0](https://crates.io/crates/rocket/0.5.0)

Example of generated documentation using Okapi:
- DF Storyteller: [RapiDoc](https://docs.dfstoryteller.com/rapidoc/),
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Ralph Bisschops <[email protected]>"]
edition = "2018"

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = ["swagger", "rapidoc"] }
serde = "1.0"
serde_json = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/dyn_templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ authors = [
edition = "2018"

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json"] }
schemars = { version = "0.8" }
rocket_okapi = { path = "../../rocket-okapi", features = ["swagger", "rapidoc", "rocket_dyn_templates"] }
serde = "1.0"
rocket_dyn_templates = {version = "=0.1.0-rc.3", features = ["handlebars"]}
rocket_dyn_templates = {version = "=0.1.0", features = ["handlebars"]}
handlebars = "4.3.0"
2 changes: 1 addition & 1 deletion examples/json-web-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors = ["Graham Esau <[email protected]>"]
edition = "2018"

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = ["swagger", "rapidoc"] }
serde = "1.0"
2 changes: 1 addition & 1 deletion examples/openapi_attributes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors = ["Ralph Bisschops <[email protected]>"]
edition = "2021"

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = ["swagger", "rapidoc"] }
serde = "1.0"
2 changes: 1 addition & 1 deletion examples/raw_identifiers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = ["rapidoc", "swagger"] }
2 changes: 1 addition & 1 deletion examples/secure_request_guard/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = ["Kristoffer Ödmark <[email protected]>", "Ralph Bisschop
edition = "2018"

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json", "secrets"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json", "secrets"] }
rocket_okapi = { path = "../../rocket-okapi", features = ["rapidoc", "swagger", "secrets"] }
serde = "1.0"
tokio = "1.6"
Expand Down
4 changes: 2 additions & 2 deletions examples/secure_request_guard/src/api_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ impl<'a> FromRequest<'a> for ApiKey {
if key == "mykey" {
Outcome::Success(ApiKey(key.to_owned()))
} else {
Outcome::Failure((Status::Unauthorized, "Api key is invalid."))
Outcome::Error((Status::Unauthorized, "Api key is invalid."))
}
}
None => Outcome::Failure((Status::BadRequest, "Missing `x-api-key` header.")),
None => Outcome::Error((Status::BadRequest, "Missing `x-api-key` header.")),
}
// For more info see: https://rocket.rs/v0.5-rc/guide/state/#within-guards
}
Expand Down
3 changes: 2 additions & 1 deletion examples/secure_request_guard/src/cookies.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! ------ Just Cookies (for just 1 route/endpoint) ------

use rocket::http::Status;
use rocket::outcome::IntoOutcome;
use rocket::serde::json::Json;
use rocket::{
Expand Down Expand Up @@ -27,7 +28,7 @@ impl<'a> FromRequest<'a> for CookieAuth {
.get_private("user_id") // Requires "secrets" feature flag
.and_then(|cookie| cookie.value().parse().ok())
.map(CookieAuth)
.or_forward(())
.or_forward(Status::Unauthorized)
}
}

Expand Down
4 changes: 2 additions & 2 deletions examples/secure_request_guard/src/http_auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ impl<'a> FromRequest<'a> for HttpAuth {
if token == "Bearer mytoken" {
Outcome::Success(HttpAuth(token.to_owned()))
} else {
Outcome::Failure((Status::Unauthorized, "Auth is invalid."))
Outcome::Error((Status::Unauthorized, "Auth is invalid."))
}
}
None => Outcome::Failure((Status::BadRequest, "Missing `Authorization` header.")),
None => Outcome::Error((Status::BadRequest, "Missing `Authorization` header.")),
}
// For more info see: https://rocket.rs/v0.5-rc/guide/state/#within-guards
}
Expand Down
4 changes: 2 additions & 2 deletions examples/secure_request_guard/src/oauth2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ impl<'a> FromRequest<'a> for OAuth2AuthCode {
if jwt.starts_with("Bearer ") {
Outcome::Success(OAuth2AuthCode)
} else {
Outcome::Failure((Status::Unauthorized, "JWT is invalid."))
Outcome::Error((Status::Unauthorized, "JWT is invalid."))
}
}
None => Outcome::Failure((Status::BadRequest, "Missing `Authorization` header.")),
None => Outcome::Error((Status::BadRequest, "Missing `Authorization` header.")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/special-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors = ["Ralph Bisschops <[email protected]>"]
edition = "2018"

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = ["swagger", "rapidoc"] }
serde = "1.0"
2 changes: 1 addition & 1 deletion examples/streams/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors = ["Ralph Bisschops <[email protected]>"]
edition = "2018"

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json"] }
rocket_okapi = { path = "../../rocket-okapi", features = ["swagger", "rapidoc"] }
serde = "1.0"
2 changes: 1 addition & 1 deletion examples/uuid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = [
edition = "2018"

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json", "uuid"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json", "uuid"] }
schemars = { version = "0.8", features = ["uuid1"] }
rocket_okapi = { path = "../../rocket-okapi", features = ["swagger", "rapidoc", "uuid"] }
serde = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion rocket-okapi-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = ["web-programming"]
proc-macro = true

[dependencies]
rocket_http = { version = "=0.5.0-rc.3" }
rocket_http = { version = "=0.5.0" }
darling = "0.13"
syn = "1.0"
proc-macro2 = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions rocket-okapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["rust", "openapi", "swagger", "rocket"]
categories = ["web-programming"]

[dependencies]
rocket = { version = "=0.5.0-rc.3", default-features = false, features = ["json"] }
rocket = { version = "=0.5.0", default-features = false, features = ["json"] }
schemars = { version = "0.8.10" }
okapi = { version = "0.7.0-rc.1", path = "../okapi" }
rocket_okapi_codegen = { version = "=0.8.0-rc.3", path = "../rocket-okapi-codegen" }
Expand All @@ -23,8 +23,8 @@ log = "0.4"
# time = { version = "0.2.27" }
# Rocket dependency but not re-exported
either = "1"
rocket_dyn_templates = { version = "=0.1.0-rc.3", optional = true }
rocket_db_pools = { version = "=0.1.0-rc.3", optional = true }
rocket_dyn_templates = { version = "=0.1.0", optional = true }
rocket_db_pools = { version = "=0.1.0", optional = true }

[dev-dependencies]
rocket_sync_db_pools = { version = "0.1.0-rc.3", features = ["diesel_sqlite_pool"] }
Expand Down
6 changes: 3 additions & 3 deletions rocket-okapi/src/handlers/content.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rocket::http::{ContentType, Method};
use rocket::http::{ContentType, Method, Status};
use rocket::response::Responder;
use rocket::route::{Handler, Outcome};
use rocket::{Data, Request, Route};
Expand Down Expand Up @@ -56,12 +56,12 @@ where
async fn handle<'r>(&self, req: &'r Request<'_>, data: Data<'r>) -> Outcome<'r> {
// match e.g. "/index.html" but not "/index.html/"
if req.uri().path().ends_with('/') {
Outcome::forward(data)
Outcome::forward(data, Status::PermanentRedirect)
} else {
let content: (_, Vec<u8>) = (self.content.0.clone(), self.content.1.as_ref().into());
match content.respond_to(req) {
Ok(response) => Outcome::Success(response),
Err(status) => Outcome::Failure(status),
Err(status) => Outcome::Error(status),
}
}
}
Expand Down

0 comments on commit df597f0

Please sign in to comment.