Remove conflicting serde attributes from single-field structs#1271
Closed
Remove conflicting serde attributes from single-field structs#1271
Conversation
For single-field structs, #[serde(flatten)] on the field is functionally equivalent to #[serde(transparent)] on the struct. Removed #[serde(transparent)] because it's not supported by WpContextual (generated types) and WpDeserialize (sparse types). Also removed #[serde(rename)] from flattened fields as it conflicts with the flatten behavior.
#[serde(transparent)] and conflicting #[serde(rename)]
Collaborator
XCFramework BuildThis PR's XCFramework is available for testing. Add to your .package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1271")Built from 07aa8ab |
jkmassel
requested changes
Apr 8, 2026
Contributor
jkmassel
left a comment
There was a problem hiding this comment.
I think this approach could fail (though it's probably unlikely).
For example:
// wp_api/src/post_types.rs — inside mod test {}
#[test]
fn test_post_type_supports_map_from_empty_array() {
// WordPress returns `[]` instead of `{}` when a post type has no
// supported features (e.g. `register_post_type('foo', ['supports' => false])`).
let json = r#"[]"#;
let supports: PostTypeSupportsMap =
serde_json::from_str(json).expect("Should handle empty array from WordPress API");
assert!(supports.map.is_empty());
}
// wp_api/src/users.rs — inside mod tests {}
#[test]
fn test_user_capabilities_map_from_empty_array() {
// WordPress returns `[]` instead of `{}` when a map is empty.
let json = r#"[]"#;
let caps: UserCapabilitiesMap =
serde_json::from_str(json).expect("Should handle empty array from WordPress API");
assert!(caps.map.is_empty());
}It's probably vanishingly rare, but I think we need to handle the empty case?
Contributor
Author
|
@jkmassel Thank you for catching that. I'm working on a different way to address this conflict, so I'll close this PR and open a new one when I am ready. I'll also make sure to add the tests you provided so they are part of our coverage. |
Contributor
Author
|
#1273 should address the issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removed
#[serde(transparent)]and conflicting#[serde(rename)]attributes from single-field wrapper structs.Changes
Removed
#[serde(transparent)]from 6 structs:UserCapabilitiesMapPostTypeSupportsMapSparsePostTypesResponseSparseTaxonomyTypesResponseSparseMenuLocationsResponseSparsePostStatusesResponseRemoved
#[serde(rename)]fromUserCapabilitiesMapandPostTypeSupportsMapRationale
For single-field structs,
#[serde(flatten)]on the field is functionally equivalent to#[serde(transparent)]on the struct.#[serde(transparent)]is not supported by:WpContextual(generates concrete types withouttransparent)WpDeserialize(explicitly rejectstransparentattribute)#[serde(rename)]conflicts with#[serde(flatten)]which takes all keys from the parent object.