Skip to content

Commit

Permalink
fix: support leading ascii whitespace (#434)
Browse files Browse the repository at this point in the history
* remove unnecessary seek trait

* add support for leading ascii whitespace

* remove extraneous curly braces

* fix two 'useless use of `format!` errors that occurred during `make all`

* fix a &bool/bool E0308 error
  • Loading branch information
mxndtaylor authored Jun 4, 2022
1 parent 1a5ae61 commit 43cfea1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions macros/src/actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
13 changes: 7 additions & 6 deletions src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -109,14 +109,15 @@ pub use paperclip_core::{
/// JSON and YAML formats.
pub fn from_reader<R, S>(mut reader: R) -> Result<ResolvableApi<S>, 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<S>>(reader)?,
Expand Down

0 comments on commit 43cfea1

Please sign in to comment.