diff --git a/native/kotlin/api/kotlin/src/integrationTest/kotlin/PostTypesEndpointTest.kt b/native/kotlin/api/kotlin/src/integrationTest/kotlin/PostTypesEndpointTest.kt index b1a5f31c..f954e803 100644 --- a/native/kotlin/api/kotlin/src/integrationTest/kotlin/PostTypesEndpointTest.kt +++ b/native/kotlin/api/kotlin/src/integrationTest/kotlin/PostTypesEndpointTest.kt @@ -26,7 +26,7 @@ class PostTypesEndpointTest { val postTypesPost = client.request { requestBuilder -> requestBuilder.postTypes().retrieveWithEditContext(PostType.Post) }.assertSuccessAndRetrieveData().data - assert(postTypesPost.supports[PostTypeSupports.Title]!!) + assert(postTypesPost.supports.map[PostTypeSupports.Title]!!) assertFalse(postTypesPost.capabilities[PostTypeCapabilities.EditPosts]!!.isEmpty()) } @@ -35,7 +35,7 @@ class PostTypesEndpointTest { val postTypesPost = client.request { requestBuilder -> requestBuilder.postTypes().retrieveWithEditContext(PostType.WpFontFace) }.assertSuccessAndRetrieveData().data - assertNull(postTypesPost.supports[PostTypeSupports.Author]) + assertNull(postTypesPost.supports.map[PostTypeSupports.Author]) } @Test diff --git a/native/swift/Example/Example/ExampleApp.swift b/native/swift/Example/Example/ExampleApp.swift index 3d4b372b..fc98e3bd 100644 --- a/native/swift/Example/Example/ExampleApp.swift +++ b/native/swift/Example/Example/ExampleApp.swift @@ -128,7 +128,7 @@ struct ExampleApp: App { .postTypes .map(\.value) .filter { $0.visibility.showInNavMenus } - .filter { $0.supports.keys.contains(allOf: [.title, .author, .customFields]) } + .filter { $0.supports.map.keys.contains(allOf: [.title, .author, .customFields]) } for type in postTypes { baseData.append(RootListData(name: type.name, sequence: { diff --git a/scripts/setup-test-site.sh b/scripts/setup-test-site.sh index b5950b45..90252b1b 100755 --- a/scripts/setup-test-site.sh +++ b/scripts/setup-test-site.sh @@ -71,7 +71,9 @@ wp import /tmp/testdata.xml --authors=create wp plugin deactivate wordpress-importer wp plugin delete wordpress-importer -wp plugin install gutenberg --activate +curl -sSL https://downloads.wordpress.org/plugin/gutenberg.21.7.0.zip -o /tmp/gutenberg.zip +unzip -q /tmp/gutenberg.zip -d wp-content/plugins/ +wp plugin activate gutenberg # Install custom must-use plugins for integration tests mkdir -p wp-content/mu-plugins diff --git a/wp_api/src/post_types.rs b/wp_api/src/post_types.rs index 54181d93..b905d5c5 100644 --- a/wp_api/src/post_types.rs +++ b/wp_api/src/post_types.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::str::FromStr; use wp_contextual::WpContextual; +use wp_serde_helper::deserialize_empty_array_or_hashmap; #[derive( Debug, @@ -74,7 +75,7 @@ pub struct SparsePostTypeDetails { #[WpContext(edit, embed, view)] pub slug: Option, #[WpContext(edit)] - pub supports: Option>, + pub supports: Option, #[WpContext(edit, view)] pub has_archive: Option, #[WpContext(edit, view)] @@ -90,6 +91,15 @@ pub struct SparsePostTypeDetails { pub icon: Option, } +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, uniffi::Record)] +#[serde(transparent)] +pub struct PostTypeSupportsMap { + #[serde(deserialize_with = "deserialize_empty_array_or_hashmap")] + #[serde(flatten)] + #[serde(rename = "supports")] + pub map: HashMap, +} + #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize, uniffi::Record)] pub struct PostTypeLabels { pub name: String, diff --git a/wp_api/src/templates.rs b/wp_api/src/templates.rs index 77800abf..08610a9e 100644 --- a/wp_api/src/templates.rs +++ b/wp_api/src/templates.rs @@ -94,6 +94,7 @@ pub struct SparseTemplate { #[WpContext(edit, embed, view)] pub slug: Option, #[WpContext(edit, embed, view)] + #[WpContextualOption] pub theme: Option, #[serde(rename = "type")] #[WpContext(edit, embed, view)] diff --git a/wp_api_integration_tests/tests/test_post_types_immut.rs b/wp_api_integration_tests/tests/test_post_types_immut.rs index aa2248fe..140cba34 100644 --- a/wp_api_integration_tests/tests/test_post_types_immut.rs +++ b/wp_api_integration_tests/tests/test_post_types_immut.rs @@ -93,7 +93,7 @@ async fn retrieve_post_types_with_edit_context( // post types might not support `Title` in which case it's perfectly fine to completely // remove this assertion. assert_eq!( - post_type.supports.get(&PostTypeSupports::Title), + post_type.supports.map.get(&PostTypeSupports::Title), Some(true).as_ref() ); // All post types in our current testing sites have `EditPost` capability, so we use this diff --git a/wp_api_integration_tests/tests/test_templates_mut.rs b/wp_api_integration_tests/tests/test_templates_mut.rs index d0008228..fe69429a 100644 --- a/wp_api_integration_tests/tests/test_templates_mut.rs +++ b/wp_api_integration_tests/tests/test_templates_mut.rs @@ -52,7 +52,7 @@ async fn create_template_with_slug_title_and_theme() { test_create_template(¶ms, |created_template| { assert_slug(&created_template); assert_title(&created_template); - assert_eq!(created_template.theme, theme); + assert_eq!(created_template.theme, Some(theme.to_string())); }) .await; }