From ad48e08bf3332ee3925cfea84ef83ce14a8cd364 Mon Sep 17 00:00:00 2001 From: mxndt Date: Sat, 28 May 2022 09:50:55 -0500 Subject: [PATCH 1/5] remove unnecessary seek trait --- src/v2/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/v2/mod.rs b/src/v2/mod.rs index 461c673f6..54c2a80b9 100644 --- a/src/v2/mod.rs +++ b/src/v2/mod.rs @@ -93,7 +93,7 @@ use crate::error::PaperClipError; use paperclip_core::v2::models::SpecFormat; use serde::Deserialize; -use std::io::{Read, Seek, SeekFrom}; +use std::io::{Read}; #[cfg(feature = "codegen")] pub use self::codegen::{DefaultEmitter, Emitter, EmitterState}; @@ -109,12 +109,12 @@ pub use paperclip_core::{ /// JSON and YAML formats. pub fn from_reader(mut reader: R) -> Result, PaperClipError> where - R: Read + Seek, + R: Read, for<'de> S: Deserialize<'de> + Schema, { let mut buf = [0; 1]; reader.read_exact(&mut buf)?; - reader.seek(SeekFrom::Start(0))?; + let reader = buf.as_ref().chain(reader); // FIXME: Support whitespaces let (mut api, fmt) = if buf[0] == b'{' { From eeea1b1b1fb834c0a5ec1accea3fddc45c0616eb Mon Sep 17 00:00:00 2001 From: mxndt Date: Sat, 28 May 2022 09:52:25 -0500 Subject: [PATCH 2/5] add support for leading ascii whitespace --- src/v2/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/v2/mod.rs b/src/v2/mod.rs index 54c2a80b9..8bbb948cc 100644 --- a/src/v2/mod.rs +++ b/src/v2/mod.rs @@ -112,11 +112,12 @@ where R: Read, for<'de> S: Deserialize<'de> + Schema, { - let mut buf = [0; 1]; - reader.read_exact(&mut buf)?; + let mut buf = [b' ']; + while &buf[0].is_ascii_whitespace() { + reader.read_exact(&mut buf)?; + } let reader = buf.as_ref().chain(reader); - // FIXME: Support whitespaces let (mut api, fmt) = if buf[0] == b'{' { ( serde_json::from_reader::<_, ResolvableApi>(reader)?, From 95a25f2a2bc1de0c6b65436a6c2a7a26bd65c897 Mon Sep 17 00:00:00 2001 From: mxndt Date: Sat, 28 May 2022 10:19:50 -0500 Subject: [PATCH 3/5] remove extraneous curly braces --- src/v2/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v2/mod.rs b/src/v2/mod.rs index 8bbb948cc..eb1beabfa 100644 --- a/src/v2/mod.rs +++ b/src/v2/mod.rs @@ -93,7 +93,7 @@ use crate::error::PaperClipError; use paperclip_core::v2::models::SpecFormat; use serde::Deserialize; -use std::io::{Read}; +use std::io::Read; #[cfg(feature = "codegen")] pub use self::codegen::{DefaultEmitter, Emitter, EmitterState}; From 3e233033c44243974ec026659a040424dad75662 Mon Sep 17 00:00:00 2001 From: mxndt Date: Sat, 28 May 2022 10:20:41 -0500 Subject: [PATCH 4/5] fix two 'useless use of `format!` errors that occured during `make all` --- macros/src/actix.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/macros/src/actix.rs b/macros/src/actix.rs index 9a3704bb0..0be04752b 100644 --- a/macros/src/actix.rs +++ b/macros/src/actix.rs @@ -1205,7 +1205,7 @@ pub fn emit_v2_header(input: TokenStream) -> TokenStream { Data::Enum(_) | Data::Union(_) => { emit_error!( item_ast.span(), - format!("Invalid data type. Apiv2Header should be defined on a struct") + "Invalid data type. Apiv2Header should be defined on a struct" ); return quote!().into(); } @@ -1218,7 +1218,7 @@ pub fn emit_v2_header(input: TokenStream) -> TokenStream { { emit_error!( item_ast.span(), - format!("Invalid openapi attribute. openapi attribute should be defined at struct fields level") + "Invalid openapi attribute. openapi attribute should be defined at struct fields level" ); return quote!().into(); } From 01929bd87647acb8504b2f868ad39fef27174b07 Mon Sep 17 00:00:00 2001 From: mxndt Date: Sat, 28 May 2022 10:23:11 -0500 Subject: [PATCH 5/5] fix a &bool/bool E0308 error --- src/v2/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v2/mod.rs b/src/v2/mod.rs index eb1beabfa..3105a30bb 100644 --- a/src/v2/mod.rs +++ b/src/v2/mod.rs @@ -113,7 +113,7 @@ where for<'de> S: Deserialize<'de> + Schema, { let mut buf = [b' ']; - while &buf[0].is_ascii_whitespace() { + while buf[0].is_ascii_whitespace() { reader.read_exact(&mut buf)?; } let reader = buf.as_ref().chain(reader);