Skip to content

Commit 450e9d2

Browse files
committed
Add an 'extras' property to comments
1 parent 503f1da commit 450e9d2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

wp_api/src/comments.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{
2-
UserAvatarSize, UserId, WpApiParamOrder, WpResponseString,
2+
JsonValue, UserAvatarSize, UserId, WpApiParamOrder, WpResponseString,
33
date::WpGmtDateTime,
44
impl_as_query_value_for_new_type, impl_as_query_value_from_to_string,
55
posts::PostId,
@@ -528,6 +528,9 @@ pub struct SparseComment {
528528
pub comment_type: Option<CommentType>,
529529
#[WpContext(edit, embed, view)]
530530
pub author_avatar_urls: Option<HashMap<UserAvatarSize, WpResponseString>>,
531+
#[serde(flatten)]
532+
#[WpContext(edit, embed, view)]
533+
pub extras: Option<JsonValue>,
531534
// meta field is omitted for now: https://github.com/Automattic/wordpress-rs/issues/422
532535
}
533536

wp_api_integration_tests/tests/test_comments_immut.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use wp_api::{
2+
JsonValue,
23
comments::{
34
CommentId, CommentListParams, CommentRetrieveParams, CommentStatus, CommentType,
45
SparseCommentFieldWithEditContext, SparseCommentFieldWithEmbedContext,
@@ -207,6 +208,23 @@ async fn list_comments_with_edit_context_parse_author_avatar_urls(
207208
});
208209
}
209210

211+
#[tokio::test]
212+
#[parallel]
213+
async fn parse_extras() {
214+
let comment = api_client()
215+
.comments()
216+
.retrieve_with_edit_context(&FIRST_COMMENT_ID, &CommentRetrieveParams::default())
217+
.await
218+
.assert_response()
219+
.data;
220+
match comment.extras {
221+
JsonValue::Object(ref map) => {
222+
assert!(map.contains_key("_links"));
223+
}
224+
_ => panic!("Expected extras to be an object"),
225+
}
226+
}
227+
210228
#[template]
211229
#[rstest]
212230
#[case::default(CommentListParams::default())]

0 commit comments

Comments
 (0)