mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-23 04:52:28 +00:00
fix some clippy warnings
This commit is contained in:
parent
147ea980bf
commit
d08d9bea8c
7 changed files with 46 additions and 48 deletions
|
@ -240,7 +240,7 @@ where
|
|||
|
||||
// get the secret from the handler, possibly decoding claims ourselves
|
||||
let secret = self.handler.jwt_secret(state, || {
|
||||
let b64 = token.split(".").nth(1)?;
|
||||
let b64 = token.split('.').nth(1)?;
|
||||
let raw = base64::decode_config(b64, base64::URL_SAFE_NO_PAD).ok()?;
|
||||
serde_json::from_slice(&raw).ok()?
|
||||
});
|
||||
|
@ -261,7 +261,7 @@ where
|
|||
};
|
||||
|
||||
// we found a valid token
|
||||
return AuthStatus::Authenticated(data);
|
||||
AuthStatus::Authenticated(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#![allow(clippy::tabs_in_doc_comments)]
|
||||
/*!
|
||||
This crate is an extension to the popular [gotham web framework][gotham] for Rust. The idea is to
|
||||
have several RESTful resources that can be added to the gotham router. This crate will take care
|
||||
|
|
|
@ -136,7 +136,7 @@ impl NewHandler for OpenapiHandler
|
|||
}
|
||||
|
||||
#[cfg(feature = "auth")]
|
||||
const SECURITY_NAME : &'static str = "authToken";
|
||||
const SECURITY_NAME : &str = "authToken";
|
||||
|
||||
#[cfg(feature = "auth")]
|
||||
fn get_security(state : &mut State) -> IndexMap<String, ReferenceOr<SecurityScheme>>
|
||||
|
@ -249,7 +249,7 @@ impl<'a> OperationParams<'a>
|
|||
{
|
||||
params.push(Item(Parameter::Path {
|
||||
parameter_data: ParameterData {
|
||||
name: param.to_string(),
|
||||
name: (*param).to_string(),
|
||||
description: None,
|
||||
required: true,
|
||||
deprecated: None,
|
||||
|
|
|
@ -9,7 +9,10 @@ use openapiv3::{
|
|||
};
|
||||
#[cfg(feature = "uuid")]
|
||||
use uuid::Uuid;
|
||||
use std::collections::{BTreeSet, HashSet};
|
||||
use std::{
|
||||
collections::{BTreeSet, HashSet},
|
||||
hash::BuildHasher
|
||||
};
|
||||
|
||||
/**
|
||||
This struct needs to be available for every type that can be part of an OpenAPI Spec. It is
|
||||
|
@ -296,7 +299,7 @@ impl<T : OpenapiType> OpenapiType for BTreeSet<T>
|
|||
}
|
||||
}
|
||||
|
||||
impl<T : OpenapiType> OpenapiType for HashSet<T>
|
||||
impl<T : OpenapiType, S : BuildHasher> OpenapiType for HashSet<T, S>
|
||||
{
|
||||
fn schema() -> OpenapiSchema
|
||||
{
|
||||
|
|
|
@ -120,6 +120,7 @@ impl Method
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum MethodArgumentType
|
||||
{
|
||||
StateRef,
|
||||
|
@ -176,9 +177,8 @@ impl Spanned for MethodArgument
|
|||
|
||||
fn interpret_arg_ty(index : usize, attrs : &[Attribute], name : &str, ty : Type) -> Result<MethodArgumentType, Error>
|
||||
{
|
||||
let attr = attrs.into_iter()
|
||||
.filter(|arg| arg.path.segments.iter().filter(|path| &path.ident.to_string() == "rest_arg").nth(0).is_some())
|
||||
.nth(0)
|
||||
let attr = attrs.iter()
|
||||
.find(|arg| arg.path.segments.iter().any(|path| &path.ident.to_string() == "rest_arg"))
|
||||
.map(|arg| arg.tokens.to_string());
|
||||
|
||||
if cfg!(feature = "auth") && (attr.as_deref() == Some("auth") || (attr.is_none() && name == "auth"))
|
||||
|
@ -219,19 +219,17 @@ fn interpret_arg(index : usize, arg : &PatType) -> Result<MethodArgument, Error>
|
|||
}
|
||||
|
||||
#[cfg(feature = "openapi")]
|
||||
fn expand_operation_id(attrs : &AttributeArgs) -> TokenStream2
|
||||
fn expand_operation_id(attrs : &[NestedMeta]) -> TokenStream2
|
||||
{
|
||||
let mut operation_id : Option<&Lit> = None;
|
||||
for meta in attrs
|
||||
{
|
||||
match meta {
|
||||
NestedMeta::Meta(Meta::NameValue(kv)) => {
|
||||
if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("operation_id".to_owned())
|
||||
{
|
||||
operation_id = Some(&kv.lit)
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
if let NestedMeta::Meta(Meta::NameValue(kv)) = meta
|
||||
{
|
||||
if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("operation_id".to_owned())
|
||||
{
|
||||
operation_id = Some(&kv.lit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,25 +245,23 @@ fn expand_operation_id(attrs : &AttributeArgs) -> TokenStream2
|
|||
}
|
||||
|
||||
#[cfg(not(feature = "openapi"))]
|
||||
fn expand_operation_id(_ : &AttributeArgs) -> TokenStream2
|
||||
fn expand_operation_id(_ : &[NestedMeta]) -> TokenStream2
|
||||
{
|
||||
quote!()
|
||||
}
|
||||
|
||||
fn expand_wants_auth(attrs : &AttributeArgs, default : bool) -> TokenStream2
|
||||
fn expand_wants_auth(attrs : &[NestedMeta], default : bool) -> TokenStream2
|
||||
{
|
||||
let default_lit = Lit::Bool(LitBool { value: default, span: Span::call_site() });
|
||||
let mut wants_auth = &default_lit;
|
||||
for meta in attrs
|
||||
{
|
||||
match meta {
|
||||
NestedMeta::Meta(Meta::NameValue(kv)) => {
|
||||
if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("wants_auth".to_owned())
|
||||
{
|
||||
wants_auth = &kv.lit
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
if let NestedMeta::Meta(Meta::NameValue(kv)) = meta
|
||||
{
|
||||
if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("wants_auth".to_owned())
|
||||
{
|
||||
wants_auth = &kv.lit
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -277,6 +273,7 @@ fn expand_wants_auth(attrs : &AttributeArgs, default : bool) -> TokenStream2
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::comparison_chain)]
|
||||
fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result<TokenStream2, Error>
|
||||
{
|
||||
let krate = super::krate();
|
||||
|
@ -381,7 +378,7 @@ fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result<To
|
|||
{
|
||||
block = quote!(#block; Default::default())
|
||||
}
|
||||
if let Some(arg) = args.iter().filter(|arg| (*arg).ty.is_database_conn()).nth(0)
|
||||
if let Some(arg) = args.iter().find(|arg| (*arg).ty.is_database_conn())
|
||||
{
|
||||
if fun_is_async
|
||||
{
|
||||
|
@ -403,7 +400,7 @@ fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result<To
|
|||
}
|
||||
};
|
||||
}
|
||||
if let Some(arg) = args.iter().filter(|arg| (*arg).ty.is_auth_status()).nth(0)
|
||||
if let Some(arg) = args.iter().find(|arg| (*arg).ty.is_auth_status())
|
||||
{
|
||||
let auth_ty = arg.ty.quote_ty();
|
||||
state_block = quote! {
|
||||
|
|
|
@ -44,22 +44,20 @@ fn expand_where(generics : &Generics) -> TokenStream2
|
|||
{
|
||||
if generics.params.is_empty()
|
||||
{
|
||||
quote!()
|
||||
return quote!();
|
||||
}
|
||||
else
|
||||
{
|
||||
let krate = super::krate();
|
||||
let idents = generics.params.iter()
|
||||
.map(|param| match param {
|
||||
GenericParam::Type(ty) => Some(ty.ident.clone()),
|
||||
_ => None
|
||||
})
|
||||
.filter(|param| param.is_some())
|
||||
.map(|param| param.unwrap());
|
||||
|
||||
quote! {
|
||||
where #(#idents : #krate::OpenapiType),*
|
||||
}
|
||||
let krate = super::krate();
|
||||
let idents = generics.params.iter()
|
||||
.map(|param| match param {
|
||||
GenericParam::Type(ty) => Some(ty.ident.clone()),
|
||||
_ => None
|
||||
})
|
||||
.filter(|param| param.is_some())
|
||||
.map(|param| param.unwrap());
|
||||
|
||||
quote! {
|
||||
where #(#idents : #krate::OpenapiType),*
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,8 +96,7 @@ fn remove_parens(input : TokenStream2) -> TokenStream2
|
|||
}
|
||||
Box::new(iter::once(tt))
|
||||
});
|
||||
let output = TokenStream2::from_iter(iter);
|
||||
output
|
||||
TokenStream2::from_iter(iter)
|
||||
}
|
||||
|
||||
fn parse_attributes(input : &[Attribute]) -> Result<Attrs, Error>
|
||||
|
|
|
@ -67,7 +67,7 @@ fn expand(tokens : TokenStream) -> Result<TokenStream2, Error>
|
|||
.filter(|attr| attr.path.segments.iter().last().map(|segment| segment.ident.to_string()) == Some("supported_types".to_string()))
|
||||
.flat_map(|attr|
|
||||
syn::parse2::<MimeList>(attr.tokens)
|
||||
.map(|list| Box::new(list.0.into_iter().map(|mime| Ok(mime))) as Box<dyn Iterator<Item = Result<Path, Error>>>)
|
||||
.map(|list| Box::new(list.0.into_iter().map(Ok)) as Box<dyn Iterator<Item = Result<Path, Error>>>)
|
||||
.unwrap_or_else(|err| Box::new(iter::once(Err(err)))))
|
||||
.collect_to_result()?;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue