diff --git a/libpaket/Cargo.toml b/libpaket/Cargo.toml index 0f7291f..a84146d 100644 --- a/libpaket/Cargo.toml +++ b/libpaket/Cargo.toml @@ -19,6 +19,7 @@ secrecy = { version = "0.8.0", features = ["serde"] } serde = { version = "1.0.195", features = ["derive"] } serde_json = "1.0.111" serde_repr = { version = "0.1.18", optional = true } +serde_ignored = "0.1" url = "2.5.0" base64 = "0.22" diff --git a/libpaket/src/login/mod.rs b/libpaket/src/login/mod.rs index 1e1faa0..e18d82a 100644 --- a/libpaket/src/login/mod.rs +++ b/libpaket/src/login/mod.rs @@ -35,7 +35,7 @@ impl OpenIdClient { .form(constants::token::refresh_token_form(refresh_token.as_str()).as_slice()) ); - parse_json_response_from_apiresult!(res, TokenResponse) + Ok(parse_json_response_from_apiresult!(res, TokenResponse)) } pub async fn token_authorization( @@ -65,6 +65,6 @@ impl OpenIdClient { let res = self.client.execute(req).await; let res = parse_response_internal!(res); - parse_json_response_from_apiresult!(res, TokenResponse) + Ok(parse_json_response_from_apiresult!(res, TokenResponse)) } } diff --git a/libpaket/src/utils.rs b/libpaket/src/utils.rs index fff6f51..befc15b 100644 --- a/libpaket/src/utils.rs +++ b/libpaket/src/utils.rs @@ -180,23 +180,46 @@ macro_rules! request_json { macro_rules! parse_json_response { ($res: expr, $type: ty) => {{ let res = $res.text().await.unwrap(); - let res = serde_json::from_str::<$type>(&res); + let jd = &mut serde_json::Deserializer::from_str(res.as_str()); + let mut unused = std::collections::BTreeSet::new(); - match res { + println!("res({}): {}", stringify!($type), res); + let res: Result<$type,_> = serde_ignored::deserialize(jd, |path| { + unused.insert(path.to_string()); + }); + println!("res({}): {:?}", stringify!($type), unused); + + let res: $type = match res { Ok(res) => res, Err(err) => return Err(crate::LibraryError::from(err)), - } + }; + + res }}; } macro_rules! parse_json_response_from_apiresult { ($res: expr, $type: ty) => {{ let res = $res.text().await.unwrap(); - let res = serde_json::from_str::>(&res); + let jd = &mut serde_json::Deserializer::from_str(res.as_str()); + let mut unused = std::collections::BTreeSet::new(); - match res { + println!("res({}): {}", stringify!($type), res); + let res: Result,_> = serde_ignored::deserialize(jd, |path| { + unused.insert(path.to_string()); + }); + println!("res({}): {:?}", stringify!($type), unused); + + let res: LibraryResult<$type> = match res { Ok(res) => res.into(), - Err(err) => Err(crate::LibraryError::from(err)), - } + Err(err) => return Err(crate::LibraryError::from(err)), + }; + + let res = match res { + Ok(res) => res, + Err(err) => return Err(crate::LibraryError::from(err)), + }; + + res }}; }