Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

433 support leading whitesapce #434

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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