Skip to main content

esi_openapi/groups/
wars.rs

1use crate::prelude::*;
2
3/// Endpoints for Wars
4pub struct WarsGroup<'a> {
5    pub(crate) esi: &'a Esi,
6}
7
8/// One side of a war.
9#[derive(Debug, Clone, PartialEq, Deserialize)]
10#[allow(missing_docs)]
11pub struct WarParty {
12    pub alliance_id: Option<i64>,
13    pub corporation_id: Option<i64>,
14    pub isk_destroyed: f64,
15    pub ships_killed: i64,
16}
17
18/// An ally of one side of a war.
19#[derive(Debug, Clone, PartialEq, Deserialize)]
20#[allow(missing_docs)]
21pub struct WarAlly {
22    pub alliance_id: Option<i64>,
23    pub corporation_id: Option<i64>,
24}
25
26/// Information about a war.
27#[derive(Debug, Clone, PartialEq, Deserialize)]
28#[allow(missing_docs)]
29pub struct War {
30    pub aggressor: WarParty,
31    pub allies: Option<Vec<WarAlly>>,
32    pub declared: String,
33    pub defender: WarParty,
34    pub finished: Option<String>,
35    pub id: i64,
36    pub mutual: bool,
37    pub open_for_allies: bool,
38    pub retracted: Option<String>,
39    pub started: Option<String>,
40}
41
42/// A killmail reference belonging to a war.
43#[derive(Debug, Clone, PartialEq, Deserialize)]
44#[allow(missing_docs)]
45pub struct WarKillmail {
46    pub killmail_hash: String,
47    pub killmail_id: i64,
48}
49
50impl WarsGroup<'_> {
51    api_get!(
52        /// List war IDs, newest first. Pass `max_war_id` to start the list below that ID.
53        list,
54        "GetWars",
55        RequestType::Public,
56        Vec<i64>,
57        ;
58        Optional(max_war_id: i64) => "max_war_id"
59    );
60
61    api_get!(
62        /// Get information about a war.
63        get_war,
64        "GetWarsWarId",
65        RequestType::Public,
66        War,
67        (war_id: i64) => "{war_id}"
68    );
69
70    api_get!(
71        /// List the killmails of a war, newest first.
72        get_war_killmails,
73        "GetWarsWarIdKillmails",
74        RequestType::Public,
75        Vec<WarKillmail>,
76        (war_id: i64) => "{war_id}";
77        Optional(page: i32) => "page"
78    );
79}
80
81#[cfg(test)]
82mod tests {
83    use super::War;
84
85    #[test]
86    fn test_parse_war_with_optional_fields_missing() {
87        let json = r#"{
88            "id": 1,
89            "declared": "2026-01-01T00:00:00Z",
90            "mutual": false,
91            "open_for_allies": true,
92            "aggressor": {"corporation_id": 7, "isk_destroyed": 1.5, "ships_killed": 2},
93            "defender": {"alliance_id": 9, "isk_destroyed": 0.0, "ships_killed": 0}
94        }"#;
95        let war: War = serde_json::from_str(json).unwrap();
96        assert_eq!(war.aggressor.corporation_id, Some(7));
97        assert!(war.finished.is_none());
98        assert!(war.allies.is_none());
99    }
100}