forked from mirror/Riven
1
0
Fork 0

adding enums to serialization

users/mingwei/surf
Mingwei Samuel 2019-10-25 22:19:00 -07:00
parent fdd1b1516c
commit 58cf643e13
20 changed files with 188 additions and 72 deletions

View File

@ -1,16 +1,27 @@
// This file is automatically generated. ///////////////////////////////////////////////
// Do not directly edit. // //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////
use std::fmt; use std::fmt;
use num_derive; use num_derive::{ FromPrimitive, ToPrimitive };
use serde_repr::{ Serialize_repr, Deserialize_repr };
/// League of Legend's champions. /// League of Legend's champions.
/// ///
/// The documentation of each variant specifies:<br> /// The documentation of each variant specifies:<br>
/// NAME (`IDENTIFIER`, ID). /// NAME (`IDENTIFIER`, ID).
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive)] #[derive(FromPrimitive, ToPrimitive)]
#[derive(Serialize_repr, Deserialize_repr)]
#[repr(i16)]
pub enum Champion { pub enum Champion {
/// A champion that doesn't exist. Used in TeamBans when no ban occured.
None = -1,
/** Aatrox (`Aatrox`, 266). */ Aatrox = 266, /** Aatrox (`Aatrox`, 266). */ Aatrox = 266,
/** Ahri (`Ahri`, 103). */ Ahri = 103, /** Ahri (`Ahri`, 103). */ Ahri = 103,
/** Akali (`Akali`, 84). */ Akali = 84, /** Akali (`Akali`, 84). */ Akali = 84,
@ -161,6 +172,7 @@ pub enum Champion {
impl Champion { impl Champion {
pub fn name(self) -> &'static str { pub fn name(self) -> &'static str {
match self { match self {
Self::None => "None",
Self::Aatrox => "Aatrox", Self::Aatrox => "Aatrox",
Self::Ahri => "Ahri", Self::Ahri => "Ahri",
Self::Akali => "Akali", Self::Akali => "Akali",
@ -311,6 +323,7 @@ impl Champion {
pub fn identifier(self) -> &'static str { pub fn identifier(self) -> &'static str {
match self { match self {
Self::None => "None",
Self::Aatrox => "Aatrox", Self::Aatrox => "Aatrox",
Self::Ahri => "Ahri", Self::Ahri => "Ahri",
Self::Akali => "Akali", Self::Akali => "Akali",

View File

@ -1,10 +1,12 @@
#![allow(deprecated)] #![allow(deprecated)]
use strum_macros::{ EnumString, Display, AsRefStr }; use strum_macros::{ EnumString, Display, AsRefStr };
use serde_repr::{ Serialize_repr, Deserialize_repr };
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(EnumString, Display, AsRefStr)] #[derive(EnumString, Display, AsRefStr)]
#[derive(Serialize_repr, Deserialize_repr)]
#[repr(u8)] #[repr(u8)]
pub enum Division { pub enum Division {
I = 1, I = 1,

View File

@ -1,5 +1,10 @@
// This file is automatically generated. ///////////////////////////////////////////////
// Do not directly edit. // //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////
use strum_macros::{ EnumString, Display, AsRefStr }; use strum_macros::{ EnumString, Display, AsRefStr };
@ -65,3 +70,5 @@ pub enum GameMode {
#[strum(to_string="ODYSSEY")] #[strum(to_string="ODYSSEY")]
Odyssey, Odyssey,
} }
serde_string!(GameMode);

View File

@ -1,5 +1,10 @@
// This file is automatically generated. ///////////////////////////////////////////////
// Do not directly edit. // //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////
use strum_macros::{ EnumString, Display, AsRefStr }; use strum_macros::{ EnumString, Display, AsRefStr };
@ -19,3 +24,5 @@ pub enum GameType {
#[strum(to_string="MATCHED_GAME")] #[strum(to_string="MATCHED_GAME")]
MatchedGame, MatchedGame,
} }
serde_string!(GameType);

View File

@ -0,0 +1,24 @@
#![macro_use]
#[macro_export]
macro_rules! serde_string {
( $x:ty ) => {
impl<'de> serde::de::Deserialize<'de> for $x
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::de::Deserializer<'de>
{
let s = String::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}
impl serde::ser::Serialize for $x {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
serializer.serialize_str(self.as_ref())
}
}
};
}

View File

@ -1,9 +1,17 @@
// This file is automatically generated. ///////////////////////////////////////////////
// Do not directly edit. // //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////
use serde_repr::{ Serialize_repr, Deserialize_repr };
/// League of Legends maps. /// League of Legends maps.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Serialize_repr, Deserialize_repr)]
#[repr(u8)] #[repr(u8)]
pub enum Map { pub enum Map {

View File

@ -1,5 +1,7 @@
//! Constant data and Enums relevant to the Riot Games API. //! Constant data and Enums relevant to the Riot Games API.
mod macro_serde_string;
mod champion; mod champion;
pub use champion::*; pub use champion::*;

View File

@ -1,5 +1,10 @@
// This file is automatically generated. ///////////////////////////////////////////////
// Do not directly edit. // //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////
#![allow(deprecated)] #![allow(deprecated)]
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };

View File

@ -18,6 +18,8 @@ pub enum QueueType {
RankedTft, RankedTft,
} }
serde_string!(QueueType);
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;

View File

@ -1,9 +1,17 @@
// This file is automatically generated. ///////////////////////////////////////////////
// Do not directly edit. // //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////
use serde_repr::{ Serialize_repr, Deserialize_repr };
/// League of Legends matchmaking seasons. /// League of Legends matchmaking seasons.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Serialize_repr, Deserialize_repr)]
#[repr(u8)] #[repr(u8)]
pub enum Season { pub enum Season {
Preseason3 = 0, Preseason3 = 0,

View File

@ -1,6 +1,10 @@
use serde_repr::{ Serialize_repr, Deserialize_repr };
/// League of Legends team.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, Ord, PartialOrd)] #[derive(Eq, PartialEq, Hash, Ord, PartialOrd)]
/// League of Legends team. #[derive(Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum Team { pub enum Team {
/// Blue team (bottom left on Summoner's Rift). /// Blue team (bottom left on Summoner's Rift).
Blue = 100, Blue = 100,

View File

@ -18,6 +18,8 @@ pub enum Tier {
#[strum(to_string="CHALLENGER")] Challenger = 240, #[strum(to_string="CHALLENGER")] Challenger = 240,
} }
serde_string!(Tier);
impl Tier { impl Tier {
/// If this tier is "standard". /// If this tier is "standard".
/// Standard means non-apex (not master+), and not unranked. /// Standard means non-apex (not master+), and not unranked.

View File

@ -1,5 +1,10 @@
// This file is automatically generated. ///////////////////////////////////////////////
// Do not directly edit. // //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////
// http://www.mingweisamuel.com/riotapi-schema/tool/ // http://www.mingweisamuel.com/riotapi-schema/tool/
// Version b2fb0513c3cdb6baa0ba78bd2a50b43670161980 // Version b2fb0513c3cdb6baa0ba78bd2a50b43670161980
@ -125,7 +130,7 @@ impl<'a> ChampionMasteryV4<'a> {
/// * `region` - Region to query. /// * `region` - Region to query.
/// * `championId` - Champion ID to retrieve Champion Mastery for /// * `championId` - Champion ID to retrieve Champion Mastery for
/// * `encryptedSummonerId` - Summoner ID associated with the player /// * `encryptedSummonerId` - Summoner ID associated with the player
pub fn get_champion_mastery(&self, region: Region, encrypted_summoner_id: &str, champion_id: i64) pub fn get_champion_mastery(&self, region: Region, encrypted_summoner_id: &str, champion_id: crate::consts::Champion)
-> impl Future<Output = Result<Option<champion_mastery_v4::ChampionMastery>>> + 'a -> impl Future<Output = Result<Option<champion_mastery_v4::ChampionMastery>>> + 'a
{ {
let path_string = format!("/lol/champion-mastery/v4/champion-masteries/by-summoner/{}/by-champion/{}", encrypted_summoner_id, champion_id); let path_string = format!("/lol/champion-mastery/v4/champion-masteries/by-summoner/{}/by-champion/{}", encrypted_summoner_id, champion_id);
@ -184,7 +189,7 @@ impl<'a> LeagueExpV4<'a> {
/// * `tier` /// * `tier`
/// * `division` /// * `division`
/// * `page` (optional) - Starts with page 1. /// * `page` (optional) - Starts with page 1.
pub fn get_league_entries(&self, region: Region, division: &str, tier: &str, queue: &str, page: Option<i32>) pub fn get_league_entries(&self, region: Region, division: crate::consts::Division, tier: crate::consts::Tier, queue: crate::consts::QueueType, page: Option<i32>)
-> impl Future<Output = Result<Option<Vec<league_exp_v4::LeagueEntry>>>> + 'a -> impl Future<Output = Result<Option<Vec<league_exp_v4::LeagueEntry>>>> + 'a
{ {
let mut query_params = Serializer::new(String::new()); let mut query_params = Serializer::new(String::new());
@ -209,7 +214,7 @@ impl<'a> LeagueV4<'a> {
/// # Parameters /// # Parameters
/// * `region` - Region to query. /// * `region` - Region to query.
/// * `queue` /// * `queue`
pub fn get_challenger_league(&self, region: Region, queue: &str) pub fn get_challenger_league(&self, region: Region, queue: crate::consts::QueueType)
-> impl Future<Output = Result<Option<league_v4::LeagueList>>> + 'a -> impl Future<Output = Result<Option<league_v4::LeagueList>>> + 'a
{ {
let path_string = format!("/lol/league/v4/challengerleagues/by-queue/{}", queue); let path_string = format!("/lol/league/v4/challengerleagues/by-queue/{}", queue);
@ -238,7 +243,7 @@ impl<'a> LeagueV4<'a> {
/// * `tier` /// * `tier`
/// * `queue` - Note that the queue value must be a valid ranked queue. /// * `queue` - Note that the queue value must be a valid ranked queue.
/// * `page` (optional) - Starts with page 1. /// * `page` (optional) - Starts with page 1.
pub fn get_league_entries(&self, region: Region, queue: &str, tier: &str, division: &str, page: Option<i32>) pub fn get_league_entries(&self, region: Region, queue: crate::consts::QueueType, tier: crate::consts::Tier, division: crate::consts::Division, page: Option<i32>)
-> impl Future<Output = Result<Option<Vec<league_v4::LeagueEntry>>>> + 'a -> impl Future<Output = Result<Option<Vec<league_v4::LeagueEntry>>>> + 'a
{ {
let mut query_params = Serializer::new(String::new()); let mut query_params = Serializer::new(String::new());
@ -254,7 +259,7 @@ impl<'a> LeagueV4<'a> {
/// # Parameters /// # Parameters
/// * `region` - Region to query. /// * `region` - Region to query.
/// * `queue` /// * `queue`
pub fn get_grandmaster_league(&self, region: Region, queue: &str) pub fn get_grandmaster_league(&self, region: Region, queue: crate::consts::QueueType)
-> impl Future<Output = Result<Option<league_v4::LeagueList>>> + 'a -> impl Future<Output = Result<Option<league_v4::LeagueList>>> + 'a
{ {
let path_string = format!("/lol/league/v4/grandmasterleagues/by-queue/{}", queue); let path_string = format!("/lol/league/v4/grandmasterleagues/by-queue/{}", queue);
@ -280,7 +285,7 @@ impl<'a> LeagueV4<'a> {
/// # Parameters /// # Parameters
/// * `region` - Region to query. /// * `region` - Region to query.
/// * `queue` /// * `queue`
pub fn get_master_league(&self, region: Region, queue: &str) pub fn get_master_league(&self, region: Region, queue: crate::consts::QueueType)
-> impl Future<Output = Result<Option<league_v4::LeagueList>>> + 'a -> impl Future<Output = Result<Option<league_v4::LeagueList>>> + 'a
{ {
let path_string = format!("/lol/league/v4/masterleagues/by-queue/{}", queue); let path_string = format!("/lol/league/v4/masterleagues/by-queue/{}", queue);

View File

@ -1,5 +1,10 @@
// This file is automatically generated. ///////////////////////////////////////////////
// Do not directly edit. // //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////
// http://www.mingweisamuel.com/riotapi-schema/tool/ // http://www.mingweisamuel.com/riotapi-schema/tool/
// Version b2fb0513c3cdb6baa0ba78bd2a50b43670161980 // Version b2fb0513c3cdb6baa0ba78bd2a50b43670161980
@ -24,7 +29,7 @@ pub mod champion_mastery_v4 {
pub champion_points: i32, pub champion_points: i32,
/// Champion ID for this entry. /// Champion ID for this entry.
#[serde(rename = "championId")] #[serde(rename = "championId")]
pub champion_id: i64, pub champion_id: crate::consts::Champion,
/// Number of points needed to achieve next level. Zero if player reached maximum champion level for this champion. /// Number of points needed to achieve next level. Zero if player reached maximum champion level for this champion.
#[serde(rename = "championPointsUntilNextLevel")] #[serde(rename = "championPointsUntilNextLevel")]
pub champion_points_until_next_level: i64, pub champion_points_until_next_level: i64,
@ -67,7 +72,7 @@ pub mod league_exp_v4 {
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
pub struct LeagueEntry { pub struct LeagueEntry {
#[serde(rename = "queueType")] #[serde(rename = "queueType")]
pub queue_type: String, pub queue_type: crate::consts::QueueType,
#[serde(rename = "summonerName")] #[serde(rename = "summonerName")]
pub summoner_name: String, pub summoner_name: String,
#[serde(rename = "hotStreak")] #[serde(rename = "hotStreak")]
@ -83,7 +88,7 @@ pub mod league_exp_v4 {
#[serde(rename = "losses")] #[serde(rename = "losses")]
pub losses: i32, pub losses: i32,
#[serde(rename = "rank")] #[serde(rename = "rank")]
pub rank: String, pub rank: crate::consts::Division,
#[serde(rename = "leagueId")] #[serde(rename = "leagueId")]
pub league_id: String, pub league_id: String,
#[serde(rename = "inactive")] #[serde(rename = "inactive")]
@ -91,7 +96,7 @@ pub mod league_exp_v4 {
#[serde(rename = "freshBlood")] #[serde(rename = "freshBlood")]
pub fresh_blood: bool, pub fresh_blood: bool,
#[serde(rename = "tier")] #[serde(rename = "tier")]
pub tier: String, pub tier: crate::consts::Tier,
/// Player's summonerId (Encrypted) /// Player's summonerId (Encrypted)
#[serde(rename = "summonerId")] #[serde(rename = "summonerId")]
pub summoner_id: String, pub summoner_id: String,
@ -123,11 +128,11 @@ pub mod league_v4 {
#[serde(rename = "leagueId")] #[serde(rename = "leagueId")]
pub league_id: String, pub league_id: String,
#[serde(rename = "tier")] #[serde(rename = "tier")]
pub tier: String, pub tier: crate::consts::Tier,
#[serde(rename = "entries")] #[serde(rename = "entries")]
pub entries: std::vec::Vec<LeagueItem>, pub entries: std::vec::Vec<LeagueItem>,
#[serde(rename = "queue")] #[serde(rename = "queue")]
pub queue: String, pub queue: crate::consts::QueueType,
#[serde(rename = "name")] #[serde(rename = "name")]
pub name: String, pub name: String,
} }
@ -154,7 +159,7 @@ pub mod league_v4 {
#[serde(rename = "inactive")] #[serde(rename = "inactive")]
pub inactive: bool, pub inactive: bool,
#[serde(rename = "rank")] #[serde(rename = "rank")]
pub rank: String, pub rank: crate::consts::Division,
/// Player's summonerId (Encrypted) /// Player's summonerId (Encrypted)
#[serde(rename = "summonerId")] #[serde(rename = "summonerId")]
pub summoner_id: String, pub summoner_id: String,
@ -179,7 +184,7 @@ pub mod league_v4 {
#[derive(serde::Serialize, serde::Deserialize)] #[derive(serde::Serialize, serde::Deserialize)]
pub struct LeagueEntry { pub struct LeagueEntry {
#[serde(rename = "queueType")] #[serde(rename = "queueType")]
pub queue_type: String, pub queue_type: crate::consts::QueueType,
#[serde(rename = "summonerName")] #[serde(rename = "summonerName")]
pub summoner_name: String, pub summoner_name: String,
#[serde(rename = "hotStreak")] #[serde(rename = "hotStreak")]
@ -195,7 +200,7 @@ pub mod league_v4 {
#[serde(rename = "losses")] #[serde(rename = "losses")]
pub losses: i32, pub losses: i32,
#[serde(rename = "rank")] #[serde(rename = "rank")]
pub rank: String, pub rank: crate::consts::Division,
#[serde(rename = "leagueId")] #[serde(rename = "leagueId")]
pub league_id: String, pub league_id: String,
#[serde(rename = "inactive")] #[serde(rename = "inactive")]
@ -203,7 +208,7 @@ pub mod league_v4 {
#[serde(rename = "freshBlood")] #[serde(rename = "freshBlood")]
pub fresh_blood: bool, pub fresh_blood: bool,
#[serde(rename = "tier")] #[serde(rename = "tier")]
pub tier: String, pub tier: crate::consts::Tier,
/// Player's summonerId (Encrypted) /// Player's summonerId (Encrypted)
#[serde(rename = "summonerId")] #[serde(rename = "summonerId")]
pub summoner_id: String, pub summoner_id: String,
@ -299,10 +304,10 @@ pub mod match_v4 {
pub struct Match { pub struct Match {
/// Please refer to the Game Constants documentation. /// Please refer to the Game Constants documentation.
#[serde(rename = "seasonId")] #[serde(rename = "seasonId")]
pub season_id: i32, pub season_id: crate::consts::Season,
/// Please refer to the Game Constants documentation. /// Please refer to the Game Constants documentation.
#[serde(rename = "queueId")] #[serde(rename = "queueId")]
pub queue_id: i32, pub queue_id: crate::consts::Queue,
#[serde(rename = "gameId")] #[serde(rename = "gameId")]
pub game_id: i64, pub game_id: i64,
/// Participant identity information. /// Participant identity information.
@ -316,13 +321,13 @@ pub mod match_v4 {
pub platform_id: String, pub platform_id: String,
/// Please refer to the Game Constants documentation. /// Please refer to the Game Constants documentation.
#[serde(rename = "gameMode")] #[serde(rename = "gameMode")]
pub game_mode: String, pub game_mode: crate::consts::GameMode,
/// Please refer to the Game Constants documentation. /// Please refer to the Game Constants documentation.
#[serde(rename = "mapId")] #[serde(rename = "mapId")]
pub map_id: i32, pub map_id: crate::consts::Map,
/// Please refer to the Game Constants documentation. /// Please refer to the Game Constants documentation.
#[serde(rename = "gameType")] #[serde(rename = "gameType")]
pub game_type: String, pub game_type: crate::consts::GameType,
/// Team information. /// Team information.
#[serde(rename = "teams")] #[serde(rename = "teams")]
pub teams: std::vec::Vec<TeamStats>, pub teams: std::vec::Vec<TeamStats>,
@ -401,7 +406,7 @@ pub mod match_v4 {
pub first_blood: bool, pub first_blood: bool,
/// 100 for blue side. 200 for red side. /// 100 for blue side. 200 for red side.
#[serde(rename = "teamId")] #[serde(rename = "teamId")]
pub team_id: i32, pub team_id: crate::consts::Team,
/// Flag indicating whether or not the team destroyed the first tower. /// Flag indicating whether or not the team destroyed the first tower.
#[serde(rename = "firstTower")] #[serde(rename = "firstTower")]
pub first_tower: bool, pub first_tower: bool,
@ -434,7 +439,7 @@ pub mod match_v4 {
pub pick_turn: i32, pub pick_turn: i32,
/// Banned championId. /// Banned championId.
#[serde(rename = "championId")] #[serde(rename = "championId")]
pub champion_id: i32, pub champion_id: crate::consts::Champion,
} }
/// Participant data object. This struct is automatically generated. /// Participant data object. This struct is automatically generated.
#[derive(Debug)] #[derive(Debug)]
@ -453,7 +458,7 @@ pub mod match_v4 {
pub timeline: ParticipantTimeline, pub timeline: ParticipantTimeline,
/// 100 for blue side. 200 for red side. /// 100 for blue side. 200 for red side.
#[serde(rename = "teamId")] #[serde(rename = "teamId")]
pub team_id: i32, pub team_id: crate::consts::Team,
/// Second Summoner Spell id. /// Second Summoner Spell id.
#[serde(rename = "spell2Id")] #[serde(rename = "spell2Id")]
pub spell2_id: i32, pub spell2_id: i32,
@ -463,12 +468,12 @@ pub mod match_v4 {
/// Highest ranked tier achieved for the previous season in a specific subset of queueIds, if any, otherwise null. Used to display border in game loading screen. Please refer to the Ranked Info documentation. /// Highest ranked tier achieved for the previous season in a specific subset of queueIds, if any, otherwise null. Used to display border in game loading screen. Please refer to the Ranked Info documentation.
/// (Legal values: CHALLENGER, MASTER, DIAMOND, PLATINUM, GOLD, SILVER, BRONZE, UNRANKED) /// (Legal values: CHALLENGER, MASTER, DIAMOND, PLATINUM, GOLD, SILVER, BRONZE, UNRANKED)
#[serde(rename = "highestAchievedSeasonTier")] #[serde(rename = "highestAchievedSeasonTier")]
pub highest_achieved_season_tier: String, pub highest_achieved_season_tier: crate::consts::Tier,
/// First Summoner Spell id. /// First Summoner Spell id.
#[serde(rename = "spell1Id")] #[serde(rename = "spell1Id")]
pub spell1_id: i32, pub spell1_id: i32,
#[serde(rename = "championId")] #[serde(rename = "championId")]
pub champion_id: i32, pub champion_id: crate::consts::Champion,
} }
/// ParticipantStats data object. This struct is automatically generated. /// ParticipantStats data object. This struct is automatically generated.
#[derive(Debug)] #[derive(Debug)]
@ -793,13 +798,13 @@ pub mod match_v4 {
#[serde(rename = "gameId")] #[serde(rename = "gameId")]
pub game_id: i64, pub game_id: i64,
#[serde(rename = "champion")] #[serde(rename = "champion")]
pub champion: i32, pub champion: crate::consts::Champion,
#[serde(rename = "platformId")] #[serde(rename = "platformId")]
pub platform_id: String, pub platform_id: String,
#[serde(rename = "season")] #[serde(rename = "season")]
pub season: i32, pub season: i32,
#[serde(rename = "queue")] #[serde(rename = "queue")]
pub queue: i32, pub queue: crate::consts::Queue,
#[serde(rename = "role")] #[serde(rename = "role")]
pub role: String, pub role: String,
#[serde(rename = "timestamp")] #[serde(rename = "timestamp")]
@ -868,7 +873,7 @@ pub mod match_v4 {
#[serde(rename = "towerType")] #[serde(rename = "towerType")]
pub tower_type: String, pub tower_type: String,
#[serde(rename = "teamId")] #[serde(rename = "teamId")]
pub team_id: i32, pub team_id: crate::consts::Team,
#[serde(rename = "ascendedType")] #[serde(rename = "ascendedType")]
pub ascended_type: String, pub ascended_type: String,
#[serde(rename = "killerId")] #[serde(rename = "killerId")]
@ -931,13 +936,13 @@ pub mod spectator_v4 {
pub platform_id: String, pub platform_id: String,
/// The game mode /// The game mode
#[serde(rename = "gameMode")] #[serde(rename = "gameMode")]
pub game_mode: String, pub game_mode: crate::consts::GameMode,
/// The ID of the map /// The ID of the map
#[serde(rename = "mapId")] #[serde(rename = "mapId")]
pub map_id: i64, pub map_id: crate::consts::Map,
/// The game type /// The game type
#[serde(rename = "gameType")] #[serde(rename = "gameType")]
pub game_type: String, pub game_type: crate::consts::GameType,
/// Banned champion information /// Banned champion information
#[serde(rename = "bannedChampions")] #[serde(rename = "bannedChampions")]
pub banned_champions: std::vec::Vec<BannedChampion>, pub banned_champions: std::vec::Vec<BannedChampion>,
@ -952,7 +957,7 @@ pub mod spectator_v4 {
pub game_length: i64, pub game_length: i64,
/// The queue type (queue types are documented on the Game Constants page) /// The queue type (queue types are documented on the Game Constants page)
#[serde(rename = "gameQueueConfigId")] #[serde(rename = "gameQueueConfigId")]
pub game_queue_config_id: i64, pub game_queue_config_id: crate::consts::Queue,
} }
/// BannedChampion data object. This struct is automatically generated. /// BannedChampion data object. This struct is automatically generated.
#[derive(Debug)] #[derive(Debug)]
@ -963,10 +968,10 @@ pub mod spectator_v4 {
pub pick_turn: i32, pub pick_turn: i32,
/// The ID of the banned champion /// The ID of the banned champion
#[serde(rename = "championId")] #[serde(rename = "championId")]
pub champion_id: i64, pub champion_id: crate::consts::Champion,
/// The ID of the team that banned the champion /// The ID of the team that banned the champion
#[serde(rename = "teamId")] #[serde(rename = "teamId")]
pub team_id: i64, pub team_id: crate::consts::Team,
} }
/// Observer data object. This struct is automatically generated. /// Observer data object. This struct is automatically generated.
#[derive(Debug)] #[derive(Debug)]
@ -985,7 +990,7 @@ pub mod spectator_v4 {
pub profile_icon_id: i64, pub profile_icon_id: i64,
/// The ID of the champion played by this participant /// The ID of the champion played by this participant
#[serde(rename = "championId")] #[serde(rename = "championId")]
pub champion_id: i64, pub champion_id: crate::consts::Champion,
/// The summoner name of this participant /// The summoner name of this participant
#[serde(rename = "summonerName")] #[serde(rename = "summonerName")]
pub summoner_name: String, pub summoner_name: String,
@ -1003,7 +1008,7 @@ pub mod spectator_v4 {
pub spell2_id: i64, pub spell2_id: i64,
/// The team ID of this participant, indicating the participant's team /// The team ID of this participant, indicating the participant's team
#[serde(rename = "teamId")] #[serde(rename = "teamId")]
pub team_id: i64, pub team_id: crate::consts::Team,
/// The ID of the first summoner spell used by this participant /// The ID of the first summoner spell used by this participant
#[serde(rename = "spell1Id")] #[serde(rename = "spell1Id")]
pub spell1_id: i64, pub spell1_id: i64,
@ -1063,14 +1068,14 @@ pub mod spectator_v4 {
/// The game mode /// The game mode
/// (Legal values: CLASSIC, ODIN, ARAM, TUTORIAL, ONEFORALL, ASCENSION, FIRSTBLOOD, KINGPORO) /// (Legal values: CLASSIC, ODIN, ARAM, TUTORIAL, ONEFORALL, ASCENSION, FIRSTBLOOD, KINGPORO)
#[serde(rename = "gameMode")] #[serde(rename = "gameMode")]
pub game_mode: String, pub game_mode: crate::consts::GameMode,
/// The ID of the map /// The ID of the map
#[serde(rename = "mapId")] #[serde(rename = "mapId")]
pub map_id: i64, pub map_id: crate::consts::Map,
/// The game type /// The game type
/// (Legal values: CUSTOM_GAME, MATCHED_GAME, TUTORIAL_GAME) /// (Legal values: CUSTOM_GAME, MATCHED_GAME, TUTORIAL_GAME)
#[serde(rename = "gameType")] #[serde(rename = "gameType")]
pub game_type: String, pub game_type: crate::consts::GameType,
/// Banned champion information /// Banned champion information
#[serde(rename = "bannedChampions")] #[serde(rename = "bannedChampions")]
pub banned_champions: std::vec::Vec<BannedChampion>, pub banned_champions: std::vec::Vec<BannedChampion>,
@ -1085,7 +1090,7 @@ pub mod spectator_v4 {
pub game_length: i64, pub game_length: i64,
/// The queue type (queue types are documented on the Game Constants page) /// The queue type (queue types are documented on the Game Constants page)
#[serde(rename = "gameQueueConfigId")] #[serde(rename = "gameQueueConfigId")]
pub game_queue_config_id: i64, pub game_queue_config_id: crate::consts::Queue,
} }
/// Participant data object. This struct is automatically generated. /// Participant data object. This struct is automatically generated.
#[derive(Debug)] #[derive(Debug)]
@ -1096,7 +1101,7 @@ pub mod spectator_v4 {
pub profile_icon_id: i64, pub profile_icon_id: i64,
/// The ID of the champion played by this participant /// The ID of the champion played by this participant
#[serde(rename = "championId")] #[serde(rename = "championId")]
pub champion_id: i64, pub champion_id: crate::consts::Champion,
/// The summoner name of this participant /// The summoner name of this participant
#[serde(rename = "summonerName")] #[serde(rename = "summonerName")]
pub summoner_name: String, pub summoner_name: String,
@ -1108,7 +1113,7 @@ pub mod spectator_v4 {
pub spell2_id: i64, pub spell2_id: i64,
/// The team ID of this participant, indicating the participant's team /// The team ID of this participant, indicating the participant's team
#[serde(rename = "teamId")] #[serde(rename = "teamId")]
pub team_id: i64, pub team_id: crate::consts::Team,
/// The ID of the first summoner spell used by this participant /// The ID of the first summoner spell used by this participant
#[serde(rename = "spell1Id")] #[serde(rename = "spell1Id")]
pub spell1_id: i64, pub spell1_id: i64,

View File

@ -14,15 +14,21 @@
}}{{= require('./dotUtils.js').preamble() }} }}{{= require('./dotUtils.js').preamble() }}
use std::fmt; use std::fmt;
use num_derive; use num_derive::{ FromPrimitive, ToPrimitive };
use serde_repr::{ Serialize_repr, Deserialize_repr };
/// League of Legend's champions. /// League of Legend's champions.
/// ///
/// The documentation of each variant specifies:<br> /// The documentation of each variant specifies:<br>
/// NAME (`IDENTIFIER`, ID). /// NAME (`IDENTIFIER`, ID).
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive)] #[derive(FromPrimitive, ToPrimitive)]
#[derive(Serialize_repr, Deserialize_repr)]
#[repr(i16)]
pub enum Champion { pub enum Champion {
/// A champion that doesn't exist. Used in TeamBans when no ban occured.
None = -1,
{{ {{
for (let { id, alias, name } of champions) { for (let { id, alias, name } of champions) {
const comment = `${name.padEnd(14)} (\`${alias}\`, ${id}).`.padEnd(36); const comment = `${name.padEnd(14)} (\`${alias}\`, ${id}).`.padEnd(36);
@ -37,6 +43,7 @@ pub enum Champion {
impl Champion { impl Champion {
pub fn name(self) -> &'static str { pub fn name(self) -> &'static str {
match self { match self {
Self::None => "None",
{{ {{
for (let { id, name } of champions) { for (let { id, name } of champions) {
}} }}
@ -49,6 +56,7 @@ impl Champion {
pub fn identifier(self) -> &'static str { pub fn identifier(self) -> &'static str {
match self { match self {
Self::None => "None",
{{ {{
for (let { name, alias } of champions) { for (let { name, alias } of champions) {
}} }}

View File

@ -22,3 +22,5 @@ pub enum GameMode {
} }
}} }}
} }
serde_string!(GameMode);

View File

@ -21,3 +21,5 @@ pub enum GameType {
} }
}} }}
} }
serde_string!(GameType);

View File

@ -5,9 +5,12 @@
dotUtils.changeCase.pascalCase(mapName.replace(/[ ']+/, ''))); dotUtils.changeCase.pascalCase(mapName.replace(/[ ']+/, '')));
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
use serde_repr::{ Serialize_repr, Deserialize_repr };
/// League of Legends maps. /// League of Legends maps.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Serialize_repr, Deserialize_repr)]
#[repr(u8)] #[repr(u8)]
pub enum Map { pub enum Map {
{{ {{

View File

@ -3,9 +3,12 @@
const seasons = require('./.seasons.json'); const seasons = require('./.seasons.json');
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
use serde_repr::{ Serialize_repr, Deserialize_repr };
/// League of Legends matchmaking seasons. /// League of Legends matchmaking seasons.
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)] #[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(Serialize_repr, Deserialize_repr)]
#[repr(u8)] #[repr(u8)]
pub enum Season { pub enum Season {
{{ {{

View File

@ -14,8 +14,14 @@ Array.prototype.groupBy = function(lambda) {
} }
function preamble() { function preamble() {
return `// This file is automatically generated. return `\
// Do not directly edit.`; ///////////////////////////////////////////////
// //
// ! //
// This file is automatically generated! //
// Do not directly edit! //
// //
///////////////////////////////////////////////`;
} }
function capitalize(input) { function capitalize(input) {
@ -41,12 +47,6 @@ function normalizePropName(propName, schemaName, value) {
if ('type' === out) if ('type' === out)
return 'r#' + out; return 'r#' + out;
return out; return out;
// return propName;
// var tokens = propName.split('_');
// var name = tokens.map(capitalize).join('');
// if (name === schemaName)
// name += stringifyType(value);
// return name;
} }
function stringifyType(prop, endpoint = null, optional = false, fullpath = true, owned = true) { function stringifyType(prop, endpoint = null, optional = false, fullpath = true, owned = true) {
@ -54,6 +54,10 @@ function stringifyType(prop, endpoint = null, optional = false, fullpath = true,
prop = prop.anyOf[0]; prop = prop.anyOf[0];
} }
let enumType = prop['x-enum'];
if (enumType && 'locale' !== enumType)
return 'crate::consts::' + changeCase.pascalCase(enumType);
let refType = prop['$ref']; let refType = prop['$ref'];
if (refType) { if (refType) {
return (!endpoint ? '' : changeCase.snakeCase(endpoint) + '::') + return (!endpoint ? '' : changeCase.snakeCase(endpoint) + '::') +