Unify on #[serde(transparent)] for single-field wrapper types#1273
Open
Unify on #[serde(transparent)] for single-field wrapper types#1273
#[serde(transparent)] for single-field wrapper types#1273Conversation
…wrapper types Previously, single-field wrapper types used both `#[serde(transparent)]` on the struct and `#[serde(flatten)]` on the field. `transparent` controlled the source struct's own deserialization, while `flatten` was propagated by `WpContextual` to generated types. This was confusing and underdocumented. Changes: - `WpContextual` now propagates serde struct-level attributes (like `#[serde(transparent)]`) to all generated types, so `#[serde(flatten)]` is no longer needed for propagation - `WpDeserialize` now supports `#[serde(transparent)]` for `Option<HashMap<K, V>>` fields, generating a custom visitor that resolves the `Option` at the `visit_map`/`visit_seq` dispatch point instead of delegating to `DeserializeEmptyVecOrT<DeserializeHelper>` - Removed `#[serde(flatten)]` and `#[serde(rename)]` from all 6 wrapper types: `UserCapabilitiesMap`, `PostTypeSupportsMap`, `SparsePostTypesResponse`, `SparseTaxonomyTypesResponse`, `SparseMenuLocationsResponse`, `SparsePostStatusesResponse` - Non-`HashMap` fields with `#[serde(transparent)]` on `WpDeserialize` produce a compile-time error
Collaborator
XCFramework BuildThis PR's XCFramework is available for testing. Add to your .package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1273")Built from 691371e |
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.
Unify on
#[serde(transparent)]and remove#[serde(flatten)]from single-field wrapper types.Previously these types used both attributes —
transparentfor the source struct,flattenfor propagation toWpContextualgenerated types. This was confusing because neither attribute was clearly the "real" one, andflatten/renamewere silently no-ops undertransparent.Changes
WpContextualnow propagates serde struct-level attributes to generated types, sotransparentflows through without needingflattenas a workaroundWpDeserializenow supports#[serde(transparent)]forOption<HashMap<K, V>>fields — generates a custom visitor that handles theOptionwrapping at thevisit_map/visit_seqdispatch pointHashMapfields with#[serde(transparent)]onWpDeserializeproduce a compile-time error#[serde(flatten)]and#[serde(rename)]from all 6 affected wrapper types