From 14dfbbba7f158db724a58c45dd44087c06ba7cee Mon Sep 17 00:00:00 2001 From: Tony Li Date: Fri, 19 Dec 2025 14:26:25 +1300 Subject: [PATCH 1/2] Add test file to reproduce a WpApiDetail parsing issue --- test-data/api-details/test-case-05.json | 78 +++++++++++++++++++++++++ wp_api/src/login.rs | 1 + 2 files changed, 79 insertions(+) create mode 100644 test-data/api-details/test-case-05.json diff --git a/test-data/api-details/test-case-05.json b/test-data/api-details/test-case-05.json new file mode 100644 index 000000000..9049b31bf --- /dev/null +++ b/test-data/api-details/test-case-05.json @@ -0,0 +1,78 @@ +{ + "name": "Example WordPress Site", + "description": "", + "url": "https://example-site.wordpress.test", + "home": "https://example-site.wordpress.test", + "gmt_offset": 13, + "timezone_string": "Pacific/Auckland", + "page_for_posts": 0, + "page_on_front": 0, + "show_on_front": "posts", + "namespaces": [ + "oembed/1.0", + "akismet/v1", + "jetpack/v4", + "tec/tickets/onboarding", + "tribe/tickets/v1", + "tribe/event-aggregator/v1", + "tribe/events/v1", + "tribe/views/v2", + "tec/v2/onboarding", + "tec/v1", + "wpcom/v2", + "jetpack/v4/stats-app", + "wpcom/v3", + "jetpack-boost/v1", + "my-jetpack/v1", + "jetpack/v4/explat", + "wp/v2", + "wp-site-health/v1", + "wp-block-editor/v1", + "wp-abilities/v1" + ], + "authentication": { + "application-passwords": { + "endpoints": { + "authorization": "https://example-site.wordpress.test/wp-admin/authorize-application.php" + } + } + }, + "routes": { + "/tribe/tickets/v1/tickets": { + "namespace": "tribe/tickets/v1", + "methods": ["GET", "POST"], + "endpoints": [ + { + "methods": ["POST"], + "ISSUE": "This plugin has a irregular `args` structure. https://github.com/the-events-calendar/event-tickets", + "args": [ + { "required": false }, + { + "description": { + "type": "string", + "in": "body", + "validate_callback": [{}, "is_string_or_empty"], + "sanitize_callback": "sanitize_text_field", + "default": "" + }, + "required": false + } + ] + } + ], + "_links": { + "self": [ + { + "href": "https://example-site.wordpress.test/wp-json/tribe/tickets/v1/tickets" + } + ] + } + } + }, + "site_logo": 0, + "site_icon": 0, + "site_icon_url": "", + "_links": { + "help": [{ "href": "https://developer.wordpress.org/rest-api/" }] + } +} diff --git a/wp_api/src/login.rs b/wp_api/src/login.rs index 306fc45f8..2b8fec562 100644 --- a/wp_api/src/login.rs +++ b/wp_api/src/login.rs @@ -465,6 +465,7 @@ mod tests { #[case("api-details/test-case-02.json")] #[case("api-details/test-case-03.json")] #[case("api-details/test-case-04.json")] + #[case("api-details/test-case-05.json")] fn test_api_details_json(#[case] input: &str) { let json = test_json(input).expect("Failed to read test resource"); From cf95d067f5fd71d69f3127367c4b89c259d3ce60 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Fri, 19 Dec 2025 14:28:52 +1300 Subject: [PATCH 2/2] `WpEndpointArgs` now accepts all JSON types Use the `get` function to get a specific argument definition. --- wp_api/src/login.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/wp_api/src/login.rs b/wp_api/src/login.rs index 2b8fec562..c54663419 100644 --- a/wp_api/src/login.rs +++ b/wp_api/src/login.rs @@ -82,8 +82,19 @@ pub struct WpRoute { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, uniffi::Record)] pub struct WpEndpoint { pub methods: Vec, - #[serde(deserialize_with = "deserialize_empty_array_or_hashmap")] - pub args: HashMap, + pub args: Arc, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, uniffi::Object)] +#[serde(transparent)] +pub struct WpEndpointArgs(serde_json::Value); + +impl WpEndpointArgs { + pub fn get(&self, arg: &str) -> Option { + let obj = self.0.as_object()?; + let value = obj.get(arg)?; + serde_json::from_value(value.clone()).ok() + } } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, uniffi::Record)]