fix(buffa): re-export serde_json so extension JSON deserialize compiles without a direct consumer dep#112
Merged
Merged
Conversation
…es without a direct consumer dep Generated `Deserialize` impls for messages with `extensions N to M;` ranges and `json=true` codegen buffer `"[pkg.ext]"` JSON keys into a `serde_json::Value` before dispatching to `extension_registry::deserialize_extension_key`. The emitted path was a bare `::serde_json::Value`, which silently required every consumer of `json=true` codegen to declare `serde_json` directly in its own `Cargo.toml`. `buf/validate/validate.proto` declares 21 such extension ranges, so any SDK generated from a proto module that depends on protovalidate failed to compile with `cannot find serde_json in the crate root` unless the consumer happened to also use serde_json themselves. Re-export `serde_json` from `buffa` (gated on the `json` feature, `#[doc(hidden)]`, matching the existing `bytes` re-export) and route the codegen path through `::buffa::serde_json::Value`. `serde` itself deliberately stays a direct consumer dep: the `#[derive(::serde::Serialize)]` macro emits `extern crate serde as _serde;` by default, which a re-export alone cannot satisfy without stamping `#[serde(crate = "...")]` on every generated derive. No checked-in generated code changes — none of the WKTs declare extension ranges, so `task gen-wkt-types` is a no-op for this path.
|
All contributors have signed the CLA ✍️ ✅ |
rpb-ant
approved these changes
May 13, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Part 1/3 of the
buf/validate/validate.protobuild fix (alongside #114 and #115 — issue context in #113).Buf reported that the
bufbuild_registry_anthropics_buffaSDK (generated from the BSR with the buffa plugin,json=true) fails to build because the generatedbuf.validate.rsreferences::serde_json::Valuebut the SDK'sCargo.tomldoesn't declareserde_json.The path comes from the hand-written
Deserializeimpl emitted for messages withextensions N to M;ranges (validate.proto declares 21 of them). It buffers"[pkg.ext]"JSON keys into aserde_json::Valuebefore dispatching toextension_registry::deserialize_extension_key. Because the emitted path is a bare::serde_json::Value, every consumer ofjson=truecodegen silently picks up a hard requirement on a directserde_jsondep — a footgun the BSR plugin config (which only declaresbuffa,buffa-types,serde,bytes) walked into.Fix
Re-export
serde_jsonfrombuffa(gated on thejsonfeature,#[doc(hidden)], matching the existingbytesre-export) and route the codegen path through::buffa::serde_json::Value. After this change the generated SDK compiles with onlybuffa,buffa-types, andserdedeclared.serdeitself deliberately stays a direct consumer dep: the#[derive(::serde::Serialize)]macro emitsextern crate serde as _serde;by default, which a re-export alone cannot satisfy without stamping#[serde(crate = "...")]onto every generated derive (and rewriting every other emitted::serde::path). That's feasible but out of scope here; the BSR plugin already declaresserde.No checked-in generated code changes — none of the WKTs declare extension ranges, so
task gen-wkt-typesis a no-op.Reproduction
Minimal repro: a crate that runs
buffa-buildagainstbuf/validate/validate.protowith.generate_json(true):Before:
21 × error[E0433]: cannot find serde_json in the crate rootAfter: those errors are gone.
(There are also
15 × error[E0433]: cannot find field_descriptor_proto in protobuffrom the same proto — that's a separate gap in the default.google.protobuf→::buffa_types::google::protobufextern_path mapping, which doesn't coverdescriptor.prototypes. Tracked in #113 and addressed by #114 + #115.)Notes
::serde_json::occurrence is preceded by::buffa::(count-equality, so it catches turbofish/trait-bound contexts too).#[doc(hidden)] pub usere-exports in CONTRIBUTING.md so a future cleanup pass doesn't remove them.docs/guide.mdto addserdeto the example[dependencies](it was always required but never shown) and clarify thatserde_jsonis only needed by the consumer's ownserde_json::to_stringcalls, not by generated code.protoc-gen-buffa/buf.plugin.yamlis still pinned to0.3and predatesjson=true— it's stale and should be bumped at release time, not here.