1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-19 06:24:45 +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

@ -352,6 +352,7 @@ examples is highly appreciated.
[example]: https://gitlab.com/msrd0/gotham-restful/tree/master/example [example]: https://gitlab.com/msrd0/gotham-restful/tree/master/example
[gotham]: https://gotham.rs/ [gotham]: https://gotham.rs/
[serde_json]: https://github.com/serde-rs/json#serde-json---- [serde_json]: https://github.com/serde-rs/json#serde-json----
[`State`]: gotham::state::State
## Versioning ## Versioning

View file

@ -130,7 +130,7 @@ impl EndpointType {
Self::ReadAll | Self::Search | Self::Create | Self::UpdateAll | Self::DeleteAll => { Self::ReadAll | Self::Search | Self::Create | Self::UpdateAll | Self::DeleteAll => {
quote!(::gotham_restful::gotham::extractor::NoopPathExtractor) quote!(::gotham_restful::gotham::extractor::NoopPathExtractor)
}, },
Self::Read | Self::Update | Self::Delete => quote!(::gotham_restful::export::IdPlaceholder::<#arg_ty>), Self::Read | Self::Update | Self::Delete => quote!(::gotham_restful::private::IdPlaceholder::<#arg_ty>),
Self::Custom { .. } => { Self::Custom { .. } => {
if self.has_placeholders().value { if self.has_placeholders().value {
arg_ty.to_token_stream() arg_ty.to_token_stream()
@ -490,7 +490,7 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
let conn_ty = arg.ty.quote_ty(); let conn_ty = arg.ty.quote_ty();
state_block = quote! { state_block = quote! {
#state_block #state_block
let repo = <::gotham_restful::export::Repo<#conn_ty>>::borrow_from(state).clone(); let repo = <::gotham_restful::private::Repo<#conn_ty>>::borrow_from(state).clone();
}; };
handle_content = quote! { handle_content = quote! {
repo.run::<_, _, ()>(move |conn| { repo.run::<_, _, ()>(move |conn| {
@ -500,7 +500,7 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
} }
Ok(quote! { Ok(quote! {
use ::gotham_restful::export::FutureExt as _; use ::gotham_restful::private::FutureExt as _;
use ::gotham_restful::gotham::state::FromState as _; use ::gotham_restful::gotham::state::FromState as _;
#state_block #state_block
async move { async move {
@ -559,7 +559,7 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
placeholders: Self::Placeholders, placeholders: Self::Placeholders,
params: Self::Params, params: Self::Params,
body: ::std::option::Option<Self::Body> body: ::std::option::Option<Self::Body>
) -> ::gotham_restful::export::BoxFuture<'a, Self::Output> { ) -> ::gotham_restful::private::BoxFuture<'a, Self::Output> {
#handle_content #handle_content
} }

View file

@ -148,7 +148,7 @@ fn expand_enum(ident: Ident, generics: Generics, attrs: Vec<Attribute>, input: D
{ {
fn schema() -> #krate::OpenapiSchema fn schema() -> #krate::OpenapiSchema
{ {
use #krate::{export::openapi::*, OpenapiSchema}; use #krate::{private::openapi::*, OpenapiSchema};
let mut enumeration : Vec<String> = Vec::new(); let mut enumeration : Vec<String> = Vec::new();
@ -261,7 +261,7 @@ fn expand_struct(ident: Ident, generics: Generics, attrs: Vec<Attribute>, input:
{ {
fn schema() -> #krate::OpenapiSchema fn schema() -> #krate::OpenapiSchema
{ {
use #krate::{export::{openapi::*, IndexMap}, OpenapiSchema}; use #krate::{private::{openapi::*, IndexMap}, OpenapiSchema};
let mut properties : IndexMap<String, ReferenceOr<Box<Schema>>> = IndexMap::new(); let mut properties : IndexMap<String, ReferenceOr<Box<Schema>>> = IndexMap::new();
let mut required : Vec<String> = Vec::new(); let mut required : Vec<String> = Vec::new();

View file

@ -32,7 +32,7 @@ fn impl_openapi_type(ident: &Ident, generics: &Generics) -> TokenStream {
{ {
fn schema() -> #krate::OpenapiSchema fn schema() -> #krate::OpenapiSchema
{ {
use #krate::{export::openapi::*, OpenapiSchema}; use #krate::{private::openapi::*, OpenapiSchema};
OpenapiSchema::new(SchemaKind::Type(Type::String(StringType { OpenapiSchema::new(SchemaKind::Type(Type::String(StringType {
format: VariantOrUnknownOrEmpty::Item(StringFormat::Binary), format: VariantOrUnknownOrEmpty::Item(StringFormat::Binary),

View file

@ -316,7 +316,7 @@ pub fn expand_resource_error(input: DeriveInput) -> Result<TokenStream> {
impl #generics #krate::IntoResponseError for #ident #generics impl #generics #krate::IntoResponseError for #ident #generics
where #( #were ),* where #( #were ),*
{ {
type Err = #krate::export::serde_json::Error; type Err = #krate::private::serde_json::Error;
fn into_response_error(self) -> Result<#krate::Response, Self::Err> fn into_response_error(self) -> Result<#krate::Response, Self::Err>
{ {

View file

@ -1,4 +1,5 @@
use crate::{AuthError, Forbidden, HeaderName}; use crate::{AuthError, Forbidden};
use cookie::CookieJar; use cookie::CookieJar;
use futures_util::{ use futures_util::{
future, future,
@ -7,7 +8,7 @@ use futures_util::{
use gotham::{ use gotham::{
anyhow, anyhow,
handler::HandlerFuture, handler::HandlerFuture,
hyper::header::{HeaderMap, AUTHORIZATION}, hyper::header::{HeaderMap, HeaderName, AUTHORIZATION},
middleware::{cookie::CookieParser, Middleware, NewMiddleware}, middleware::{cookie::CookieParser, Middleware, NewMiddleware},
state::{FromState, State} state::{FromState, State}
}; };
@ -15,6 +16,7 @@ use jsonwebtoken::{errors::ErrorKind, DecodingKey};
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use std::{marker::PhantomData, panic::RefUnwindSafe, pin::Pin}; use std::{marker::PhantomData, panic::RefUnwindSafe, pin::Pin};
#[doc(no_inline)]
pub use jsonwebtoken::Validation as AuthValidation; pub use jsonwebtoken::Validation as AuthValidation;
/// The authentication status returned by the auth middleware for each request. /// 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: 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"; const SECRET : &'static [u8; 32] = b"zlBsA2QXnkmpe0QTh8uCvtAEa4j33YAc";

View file

@ -1,8 +1,10 @@
#![warn(missing_debug_implementations, rust_2018_idioms)] #![warn(missing_debug_implementations, rust_2018_idioms)]
#![deny(broken_intra_doc_links)]
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
// can we have a lint for spaces in doc comments please? // can we have a lint for spaces in doc comments please?
#![cfg_attr(feature = "cargo-clippy", allow(clippy::tabs_in_doc_comments))] #![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 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 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 [example]: https://gitlab.com/msrd0/gotham-restful/tree/master/example
[gotham]: https://gotham.rs/ [gotham]: https://gotham.rs/
[serde_json]: https://github.com/serde-rs/json#serde-json---- [serde_json]: https://github.com/serde-rs/json#serde-json----
[`State`]: gotham::state::State
*/ */
#[cfg(all(feature = "openapi", feature = "without-openapi"))] #[cfg(all(feature = "openapi", feature = "without-openapi"))]
@ -425,18 +428,13 @@ extern crate serde;
#[doc(no_inline)] #[doc(no_inline)]
pub use gotham; pub use gotham;
#[doc(no_inline)] #[doc(no_inline)]
pub use gotham::{
hyper::{header::HeaderName, StatusCode},
state::{FromState, State}
};
#[doc(no_inline)]
pub use mime::Mime; pub use mime::Mime;
pub use gotham_restful_derive::*; pub use gotham_restful_derive::*;
/// Not public API /// Not public API
#[doc(hidden)] #[doc(hidden)]
pub mod export { pub mod private {
pub use crate::routing::PathExtractor as IdPlaceholder; pub use crate::routing::PathExtractor as IdPlaceholder;
pub use futures_util::future::{BoxFuture, FutureExt}; pub use futures_util::future::{BoxFuture, FutureExt};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,13 +5,13 @@ use crate::openapi::{
}; };
use crate::{ use crate::{
result::{ResourceError, ResourceResult}, result::{ResourceError, ResourceResult},
Endpoint, FromBody, Resource, Response, StatusCode Endpoint, FromBody, Resource, Response
}; };
use gotham::{ use gotham::{
handler::HandlerError, handler::HandlerError,
helpers::http::response::{create_empty_response, create_response}, 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, pipeline::chain::PipelineHandleChain,
router::{ router::{
builder::{DefineSingleRoute, DrawRoutes, RouterBuilder, ScopeBuilder}, builder::{DefineSingleRoute, DrawRoutes, RouterBuilder, ScopeBuilder},

View file

@ -4,6 +4,7 @@ extern crate gotham_derive;
use gotham::{ use gotham::{
hyper::{HeaderMap, Method}, hyper::{HeaderMap, Method},
router::builder::*, router::builder::*,
state::State,
test::TestServer test::TestServer
}; };
use gotham_restful::*; use gotham_restful::*;

View file

@ -1,6 +1,6 @@
#[macro_use] #[macro_use]
extern crate gotham_restful; extern crate gotham_restful;
use gotham_restful::State; use gotham::state::State;
#[derive(Resource)] #[derive(Resource)]
#[resource(read_all)] #[resource(read_all)]