1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-11 10:37:51 +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
[gotham]: https://gotham.rs/
[serde_json]: https://github.com/serde-rs/json#serde-json----
[`State`]: gotham::state::State
## Versioning

View file

@ -130,7 +130,7 @@ impl EndpointType {
Self::ReadAll | Self::Search | Self::Create | Self::UpdateAll | Self::DeleteAll => {
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 { .. } => {
if self.has_placeholders().value {
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();
state_block = quote! {
#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! {
repo.run::<_, _, ()>(move |conn| {
@ -500,7 +500,7 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
}
Ok(quote! {
use ::gotham_restful::export::FutureExt as _;
use ::gotham_restful::private::FutureExt as _;
use ::gotham_restful::gotham::state::FromState as _;
#state_block
async move {
@ -559,7 +559,7 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
placeholders: Self::Placeholders,
params: Self::Params,
body: ::std::option::Option<Self::Body>
) -> ::gotham_restful::export::BoxFuture<'a, Self::Output> {
) -> ::gotham_restful::private::BoxFuture<'a, Self::Output> {
#handle_content
}

View file

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

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},

View file

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

View file

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