I tried this code.
extern crate tokio; use mwapi_responses::prelude::*; #[query( prop="info", inprop="associatedpage", )] struct Response; #[tokio::main] async fn main() { let api = mwapi::Client::builder("https://www.mediawiki.org/w/api.php").build().await.unwrap(); let params = std::collections::HashMap::<String, String>::from_iter([ ("action".to_string(), "query".to_string()), ("prop".to_string(), "info".to_string()), ("inprop".to_string(), "associatedpage".to_string()), ("titles".to_string(), "Special:FOO".to_string()), ]); let _response: Response = api.query_response(params).await.unwrap(); println!("success"); }
The program crashed.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidJson(Error("missing field `associatedpage`", line: 0, column: 0))', src\main.rs:19:64 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
The current mwapi_responses assumes that associatedpage field would always exist but there exists a corner case where if you query a special page, this field would not exist in the response.
Environment: rustc 1.64.0 | Windows 11 | mwapi 0.4.1 | mwapi_responses 0.3.1