From 2f4d1dc65ce1e8b59b659aa982635228ac32969f Mon Sep 17 00:00:00 2001 From: Mingwei Samuel Date: Wed, 29 Dec 2021 10:04:54 -0800 Subject: [PATCH] Add match_v5::Participant champion(&self) method to handle bad champion IDs Riot: https://github.com/RiotGames/developer-relations/issues/553 https://github.com/MingweiSamuel/Riven/issues/36 --- riven/src/lib.rs | 1 + riven/src/models.rs | 3 +++ riven/src/models_impls.rs | 21 +++++++++++++++++++++ riven/srcgen/lib.rs.dt | 1 + riven/srcgen/models.rs.dt | 3 +++ 5 files changed, 29 insertions(+) create mode 100644 riven/src/models_impls.rs diff --git a/riven/src/lib.rs b/riven/src/lib.rs index 0ae3098..8c1f4f8 100644 --- a/riven/src/lib.rs +++ b/riven/src/lib.rs @@ -190,6 +190,7 @@ pub use error::*; pub mod meta; pub mod models; +mod models_impls; mod req; diff --git a/riven/src/models.rs b/riven/src/models.rs index c2248e8..a9243e8 100644 --- a/riven/src/models.rs +++ b/riven/src/models.rs @@ -820,6 +820,9 @@ pub mod match_v5 { pub champ_level: i32, /// Prior to patch 11.4, on Feb 18th, 2021, this field returned invalid championIds. We recommend determining the champion based on the championName field for matches played prior to patch 11.4. #[serde(rename = "championId")] + /// + /// Instead use [`Self::champion()`] which checks this field then parses [`Self::champion_name`]. + #[deprecated(since = "2.5.0", note = "Use `Participant.champion()` instead. Riot sometimes returns corrupted data for this field: https://github.com/RiotGames/developer-relations/issues/553")] #[serde(serialize_with = "crate::consts::Champion::serialize_result")] #[serde(deserialize_with = "crate::consts::Champion::deserialize_result")] pub champion_id: Result, diff --git a/riven/src/models_impls.rs b/riven/src/models_impls.rs new file mode 100644 index 0000000..c042724 --- /dev/null +++ b/riven/src/models_impls.rs @@ -0,0 +1,21 @@ +use crate::models::match_v5::Participant; +use crate::consts::Champion; + +impl Participant { + /// This method takes the [`Self::champion_id`] field if it is valid + /// (`Ok`), otherwise it attempts to parse [`Self::champion_name`] and + /// returns the `Result`. + /// + /// This is needed because some of Riot's [`Self::champion_id`] data is + /// corrupted, as they describe in the docs: + /// + /// > Prior to patch 11.4, on Feb 18th, 2021, this field returned invalid + /// > championIds. We recommend determining the champion based on the + /// > championName field for matches played prior to patch 11.4. + /// + /// This issue is reported here: . + pub fn champion(&self) -> Result::Err> { + #[allow(deprecated)] + self.champion_id.or_else(|_| self.champion_name.parse()) + } +} diff --git a/riven/srcgen/lib.rs.dt b/riven/srcgen/lib.rs.dt index da85783..eb59ca3 100644 --- a/riven/srcgen/lib.rs.dt +++ b/riven/srcgen/lib.rs.dt @@ -26,6 +26,7 @@ pub use error::*; pub mod meta; pub mod models; +mod models_impls; mod req; diff --git a/riven/srcgen/models.rs.dt b/riven/srcgen/models.rs.dt index 62ba1e9..8a5c30f 100644 --- a/riven/srcgen/models.rs.dt +++ b/riven/srcgen/models.rs.dt @@ -59,6 +59,9 @@ pub mod {{= dotUtils.changeCase.snakeCase(endpoint) }} { #[serde(skip_serializing_if = "Option::is_none")] {{?}} {{? 'championId' === propKey && (prop.description || '').includes('this field returned invalid championIds') }} + /// + /// Instead use [`Self::champion()`] which checks this field then parses [`Self::champion_name`]. + #[deprecated(since = "2.5.0", note = "Use `Participant.champion()` instead. Riot sometimes returns corrupted data for this field: https://github.com/RiotGames/developer-relations/issues/553")] #[serde(serialize_with = "crate::consts::Champion::serialize_result")] #[serde(deserialize_with = "crate::consts::Champion::deserialize_result")] pub {{= name }}: Result,