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(); } diff --git a/src/v2/mod.rs b/src/v2/mod.rs index 461c673f6..3105a30bb 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,14 +109,15 @@ 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 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)?,