Skip to content

Unify on #[serde(transparent)] for single-field wrapper types#1273

Open
oguzkocer wants to merge 2 commits intotrunkfrom
unify-serde-transparent
Open

Unify on #[serde(transparent)] for single-field wrapper types#1273
oguzkocer wants to merge 2 commits intotrunkfrom
unify-serde-transparent

Conversation

@oguzkocer
Copy link
Copy Markdown
Contributor

Unify on #[serde(transparent)] and remove #[serde(flatten)] from single-field wrapper types.

Previously these types used both attributes — transparent for the source struct, flatten for propagation to WpContextual generated types. This was confusing because neither attribute was clearly the "real" one, and flatten/rename were silently no-ops under transparent.

Changes

  • WpContextual now propagates serde struct-level attributes to generated types, so transparent flows through without needing flatten as a workaround
  • WpDeserialize now supports #[serde(transparent)] for Option<HashMap<K, V>> fields — generates a custom visitor that handles the Option wrapping at the visit_map/visit_seq dispatch point
  • Non-HashMap fields with #[serde(transparent)] on WpDeserialize produce a compile-time error
  • Removed #[serde(flatten)] and #[serde(rename)] from all 6 affected wrapper types

…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
@oguzkocer oguzkocer added the Rust label Apr 8, 2026
@oguzkocer oguzkocer added this to the 0.2 milestone Apr 8, 2026
@wpmobilebot
Copy link
Copy Markdown
Collaborator

wpmobilebot commented Apr 8, 2026

XCFramework Build

This PR's XCFramework is available for testing. Add to your Package.swift:

.package(url: "https://github.com/automattic/wordpress-rs", branch: "pr-build/1273")

Built from 691371e

@oguzkocer oguzkocer marked this pull request as ready for review April 8, 2026 21:16
@oguzkocer oguzkocer enabled auto-merge (squash) April 8, 2026 21:16
@oguzkocer oguzkocer requested a review from jkmassel April 8, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants