Skip to content

Add an 'extras' property to comments #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

crazytonyli
Copy link
Contributor

@oguzkocer I tried the "serde flatten" solution you mentioned in our 1:1, and it worked out great. One minor downside is that there will be additional parsing work required for all API endpoints. I tried to use RawValue to avoid that, but it does not seem to work with serde(flatten) (see serde-rs/json#1252).

WP.com endpoints may return extra information in the responses. We'll need to parse that information to support the app's functionalities. This PR introduces a mechanism to support that. We can add this block of code to the models if needed:

    #[serde(flatten)]
    #[WpContext(edit, embed, view)]
    pub extras: Option<JsonValue>,

@crazytonyli crazytonyli requested a review from oguzkocer July 16, 2025 00:41
Copy link
Contributor

@oguzkocer oguzkocer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crazytonyli I think this is a good start, but it looks like we have quite a few failing tests.

  • We could consider marking the field with #[WpContextualOption] because there won't always be extra fields. I wonder if that'd also help with de-serializing speed.
  • We might want to introduce a new type to hold the extras, instead of directly using JsonValue. This might be changed to be a uniffi::Object with some helpers in the future and having a type in advance could make things easier for us. It'd also look a bit more consistent when we use it in other types. Note that you probably need to use #[serde(transparent)] for this to work, but I don't know if #[serde(transparent)] & #[serde(flatten)] works together or not.
  • The field ordering might matter, as I believe it does for de-serializing enums. That'd be a bit of an issue, because if we accidentally put this field above others, the ones below might always be set to None. If this is an issue, we could add a check in WpContext proc macro to ensure that if there is an extra field, it's at the end. Having a specific type would also help with this.
  • If we have a separate type, we could consider moving the meta field to it. I am not so sure about this though, so just dropping it as an idea for now.

@crazytonyli
Copy link
Contributor Author

The field ordering might matter

It does not seem so: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b62029454b6f50395fbb3dfd17a8d4b4.

BTW, I'll leave this PR open until we have an API endpoint that requires this change, like the WP.com /wp/v2/comments (see https://linear.app/a8c/issue/AINFRA-939).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants