From 0bce9f411cb08c009dab8f8f1bdf3ccf49594e3c Mon Sep 17 00:00:00 2001 From: IAmTomahawkx Date: Sun, 20 Oct 2024 15:28:18 -0700 Subject: [PATCH] fix: Build for rocket 0.5.1 --- examples/secure_request_guard/src/api_key.rs | 4 ++-- examples/secure_request_guard/src/cookies.rs | 3 ++- examples/secure_request_guard/src/http_auth.rs | 4 ++-- examples/secure_request_guard/src/oauth2.rs | 4 ++-- rocket-okapi-codegen/src/openapi_attr/route_attr.rs | 1 + rocket-okapi-codegen/src/openapi_spec.rs | 2 +- rocket-okapi/Cargo.toml | 2 +- rocket-okapi/src/gen.rs | 1 + rocket-okapi/src/handlers/content.rs | 6 +++--- 9 files changed, 15 insertions(+), 12 deletions(-) diff --git a/examples/secure_request_guard/src/api_key.rs b/examples/secure_request_guard/src/api_key.rs index 2551a47..5bf44d0 100644 --- a/examples/secure_request_guard/src/api_key.rs +++ b/examples/secure_request_guard/src/api_key.rs @@ -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 } diff --git a/examples/secure_request_guard/src/cookies.rs b/examples/secure_request_guard/src/cookies.rs index b0c4d8d..1109e3a 100644 --- a/examples/secure_request_guard/src/cookies.rs +++ b/examples/secure_request_guard/src/cookies.rs @@ -6,6 +6,7 @@ use revolt_rocket_okapi::{ openapi, request::{OpenApiFromRequest, RequestHeaderInput}, }; +use rocket::http::Status; use rocket::outcome::IntoOutcome; use rocket::serde::json::Json; use rocket::{ @@ -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) } } diff --git a/examples/secure_request_guard/src/http_auth.rs b/examples/secure_request_guard/src/http_auth.rs index 4f7a7ef..646f5a2 100644 --- a/examples/secure_request_guard/src/http_auth.rs +++ b/examples/secure_request_guard/src/http_auth.rs @@ -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 } diff --git a/examples/secure_request_guard/src/oauth2.rs b/examples/secure_request_guard/src/oauth2.rs index a81f0d2..cecdb4a 100644 --- a/examples/secure_request_guard/src/oauth2.rs +++ b/examples/secure_request_guard/src/oauth2.rs @@ -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.")), } } } diff --git a/rocket-okapi-codegen/src/openapi_attr/route_attr.rs b/rocket-okapi-codegen/src/openapi_attr/route_attr.rs index 5ea83e2..2ae6a9e 100644 --- a/rocket-okapi-codegen/src/openapi_attr/route_attr.rs +++ b/rocket-okapi-codegen/src/openapi_attr/route_attr.rs @@ -7,6 +7,7 @@ use syn::spanned::Spanned; use syn::{Attribute, Meta, MetaList, NestedMeta}; #[derive(Debug)] +#[allow(dead_code)] pub struct Route { pub method: Method, pub origin: Origin<'static>, diff --git a/rocket-okapi-codegen/src/openapi_spec.rs b/rocket-okapi-codegen/src/openapi_spec.rs index 28521c0..cca666b 100644 --- a/rocket-okapi-codegen/src/openapi_spec.rs +++ b/rocket-okapi-codegen/src/openapi_spec.rs @@ -57,7 +57,7 @@ fn create_add_operations(paths: Punctuated) -> TokenStream2 { } fn fn_name_for_add_operation(mut fn_path: Path) -> Path { - let mut last_seg = fn_path.segments.last_mut().expect("syn::Path has segments"); + let last_seg = fn_path.segments.last_mut().expect("syn::Path has segments"); last_seg.ident = get_add_operation_fn_name(&last_seg.ident); fn_path } diff --git a/rocket-okapi/Cargo.toml b/rocket-okapi/Cargo.toml index 406e09f..ff3a9e2 100644 --- a/rocket-okapi/Cargo.toml +++ b/rocket-okapi/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["rust", "openapi", "swagger", "rocket"] categories = ["web-programming"] [dependencies] -rocket = { version = "0.5.0-rc.2", default-features = false, features = ["json"] } +rocket = { version = "0.5.1", default-features = false, features = ["json"] } schemars = { version = "0.8" } revolt_okapi = { version = "0.9.1", path = "../okapi" } revolt_rocket_okapi_codegen = { version = "=0.9.1", path = "../rocket-okapi-codegen" } diff --git a/rocket-okapi/src/gen.rs b/rocket-okapi/src/gen.rs index b23d4a9..62e83f1 100644 --- a/rocket-okapi/src/gen.rs +++ b/rocket-okapi/src/gen.rs @@ -10,6 +10,7 @@ use std::collections::HashMap; /// A struct that visits all `rocket::Route`s, and aggregates information about them. #[derive(Debug, Clone)] +#[allow(dead_code)] pub struct OpenApiGenerator { settings: OpenApiSettings, schema_generator: SchemaGenerator, diff --git a/rocket-okapi/src/handlers/content.rs b/rocket-okapi/src/handlers/content.rs index c353792..1269a54 100644 --- a/rocket-okapi/src/handlers/content.rs +++ b/rocket-okapi/src/handlers/content.rs @@ -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}; @@ -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) = (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), } } }