1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-05-09 08:00:41 +00:00

Reexports

This commit is contained in:
msrd0 2021-02-03 21:22:46 +00:00
parent 441a42c75e
commit af28e0d916
16 changed files with 50 additions and 34 deletions

View file

@ -1,4 +1,5 @@
use crate::{AuthError, Forbidden, HeaderName};
use crate::{AuthError, Forbidden};
use cookie::CookieJar;
use futures_util::{
future,
@ -7,7 +8,7 @@ use futures_util::{
use gotham::{
anyhow,
handler::HandlerFuture,
hyper::header::{HeaderMap, AUTHORIZATION},
hyper::header::{HeaderMap, HeaderName, AUTHORIZATION},
middleware::{cookie::CookieParser, Middleware, NewMiddleware},
state::{FromState, State}
};
@ -15,6 +16,7 @@ use jsonwebtoken::{errors::ErrorKind, DecodingKey};
use serde::de::DeserializeOwned;
use std::{marker::PhantomData, panic::RefUnwindSafe, pin::Pin};
#[doc(no_inline)]
pub use jsonwebtoken::Validation as AuthValidation;
/// The authentication status returned by the auth middleware for each request.
@ -77,7 +79,7 @@ This trait will help the auth middleware to determine the validity of an authent
A very basic implementation could look like this:
```
# use gotham_restful::{AuthHandler, State};
# use gotham_restful::{AuthHandler, gotham::state::State};
#
const SECRET : &'static [u8; 32] = b"zlBsA2QXnkmpe0QTh8uCvtAEa4j33YAc";

View file

@ -1,8 +1,10 @@
#![warn(missing_debug_implementations, rust_2018_idioms)]
#![deny(broken_intra_doc_links)]
#![forbid(unsafe_code)]
// can we have a lint for spaces in doc comments please?
#![cfg_attr(feature = "cargo-clippy", allow(clippy::tabs_in_doc_comments))]
// intra-doc links only fully work when OpenAPI is enabled
#![cfg_attr(feature = "openapi", deny(broken_intra_doc_links))]
#![cfg_attr(not(feature = "openapi"), allow(broken_intra_doc_links))]
/*!
This crate is an extension to the popular [gotham web framework][gotham] for Rust. It allows you to
create resources with assigned endpoints that aim to be a more convenient way of creating handlers
@ -402,6 +404,7 @@ examples is highly appreciated.
[example]: https://gitlab.com/msrd0/gotham-restful/tree/master/example
[gotham]: https://gotham.rs/
[serde_json]: https://github.com/serde-rs/json#serde-json----
[`State`]: gotham::state::State
*/
#[cfg(all(feature = "openapi", feature = "without-openapi"))]
@ -425,18 +428,13 @@ extern crate serde;
#[doc(no_inline)]
pub use gotham;
#[doc(no_inline)]
pub use gotham::{
hyper::{header::HeaderName, StatusCode},
state::{FromState, State}
};
#[doc(no_inline)]
pub use mime::Mime;
pub use gotham_restful_derive::*;
/// Not public API
#[doc(hidden)]
pub mod export {
pub mod private {
pub use crate::routing::PathExtractor as IdPlaceholder;
pub use futures_util::future::{BoxFuture, FutureExt};

View file

@ -1,9 +1,11 @@
use super::SECURITY_NAME;
use futures_util::{future, future::FutureExt};
use gotham::{
anyhow,
handler::{Handler, HandlerFuture, NewHandler},
helpers::http::response::create_response,
hyper::StatusCode,
state::State
};
use indexmap::IndexMap;
@ -75,7 +77,7 @@ impl Handler for OpenapiHandler {
Ok(openapi) => openapi,
Err(e) => {
error!("Unable to acquire read lock for the OpenAPI specification: {}", e);
let res = create_response(&state, crate::StatusCode::INTERNAL_SERVER_ERROR, TEXT_PLAIN, "");
let res = create_response(&state, StatusCode::INTERNAL_SERVER_ERROR, TEXT_PLAIN, "");
return future::ok((state, res)).boxed();
}
};
@ -88,12 +90,12 @@ impl Handler for OpenapiHandler {
match serde_json::to_string(&openapi) {
Ok(body) => {
let res = create_response(&state, crate::StatusCode::OK, APPLICATION_JSON, body);
let res = create_response(&state, StatusCode::OK, APPLICATION_JSON, body);
future::ok((state, res)).boxed()
},
Err(e) => {
error!("Unable to handle OpenAPI request due to error: {}", e);
let res = create_response(&state, crate::StatusCode::INTERNAL_SERVER_ERROR, TEXT_PLAIN, "");
let res = create_response(&state, StatusCode::INTERNAL_SERVER_ERROR, TEXT_PLAIN, "");
future::ok((state, res)).boxed()
}
}

View file

@ -78,7 +78,7 @@ impl OperationParams {
pub struct OperationDescription {
operation_id: Option<String>,
default_status: crate::StatusCode,
default_status: gotham::hyper::StatusCode,
accepted_types: Option<Vec<Mime>>,
schema: ReferenceOr<Schema>,
params: OperationParams,

View file

@ -1,7 +1,10 @@
#[cfg(feature = "openapi")]
use crate::OpenapiSchema;
use crate::Response;
use futures_util::future::FutureExt;
#[cfg(feature = "openapi")]
use gotham::hyper::StatusCode;
use mime::{Mime, STAR_STAR};
use serde::Serialize;
use std::{
@ -57,8 +60,8 @@ pub trait ResourceResult {
fn schema() -> OpenapiSchema;
#[cfg(feature = "openapi")]
fn default_status() -> crate::StatusCode {
crate::StatusCode::OK
fn default_status() -> StatusCode {
StatusCode::OK
}
}
@ -141,7 +144,7 @@ where
}
#[cfg(feature = "openapi")]
fn default_status() -> crate::StatusCode {
fn default_status() -> StatusCode {
Res::default_status()
}
}

View file

@ -2,7 +2,10 @@ use super::{handle_error, ResourceResult};
use crate::{IntoResponseError, Response};
#[cfg(feature = "openapi")]
use crate::{OpenapiSchema, OpenapiType};
use futures_util::{future, future::FutureExt};
#[cfg(feature = "openapi")]
use gotham::hyper::StatusCode;
use mime::Mime;
use std::{fmt::Display, future::Future, pin::Pin};
@ -58,8 +61,8 @@ impl ResourceResult for NoContent {
/// This will always be a _204 No Content_
#[cfg(feature = "openapi")]
fn default_status() -> crate::StatusCode {
crate::StatusCode::NO_CONTENT
fn default_status() -> StatusCode {
StatusCode::NO_CONTENT
}
}
@ -86,7 +89,7 @@ where
}
#[cfg(feature = "openapi")]
fn default_status() -> crate::StatusCode {
fn default_status() -> StatusCode {
NoContent::default_status()
}
}

View file

@ -1,10 +1,14 @@
use super::{handle_error, IntoResponseError, ResourceResult};
#[cfg(feature = "openapi")]
use crate::OpenapiSchema;
use crate::{FromBody, RequestBody, ResourceType, Response, StatusCode};
use crate::{FromBody, RequestBody, ResourceType, Response};
use futures_core::future::Future;
use futures_util::{future, future::FutureExt};
use gotham::hyper::body::{Body, Bytes};
use gotham::hyper::{
body::{Body, Bytes},
StatusCode
};
use mime::Mime;
#[cfg(feature = "openapi")]
use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty};

View file

@ -1,8 +1,10 @@
use super::{handle_error, into_response_helper, ResourceResult};
#[cfg(feature = "openapi")]
use crate::OpenapiSchema;
use crate::{result::ResourceError, Response, ResponseBody, StatusCode};
use crate::{result::ResourceError, Response, ResponseBody};
use futures_core::future::Future;
use gotham::hyper::StatusCode;
use mime::{Mime, APPLICATION_JSON};
use std::{error::Error, fmt::Display, pin::Pin};

View file

@ -5,13 +5,13 @@ use crate::openapi::{
};
use crate::{
result::{ResourceError, ResourceResult},
Endpoint, FromBody, Resource, Response, StatusCode
Endpoint, FromBody, Resource, Response
};
use gotham::{
handler::HandlerError,
helpers::http::response::{create_empty_response, create_response},
hyper::{body::to_bytes, header::CONTENT_TYPE, Body, HeaderMap, Method},
hyper::{body::to_bytes, header::CONTENT_TYPE, Body, HeaderMap, Method, StatusCode},
pipeline::chain::PipelineHandleChain,
router::{
builder::{DefineSingleRoute, DrawRoutes, RouterBuilder, ScopeBuilder},