mirror of
https://github.com/stoatchat/rust-okapi.git
synced 2026-06-30 21:57:54 -04:00
fix: Build for rocket 0.5.1
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>,
|
||||
|
||||
@@ -57,7 +57,7 @@ fn create_add_operations(paths: Punctuated<Path, Comma>) -> 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
|
||||
}
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user