[rust] fix: free-form object query parameters reference a nonexistent models::serde_json - #24866
Open
wiebren wants to merge 2 commits into
Open
[rust] fix: free-form object query parameters reference a nonexistent models::serde_json#24866wiebren wants to merge 2 commits into
wiebren wants to merge 2 commits into
Conversation
…t models::serde_json::Value A free-form object parameter (type: object with no properties) maps to serde_json::Value, but the api templates qualify every non-primitive, non-container parameter type with models:: - and models re-exports no serde_json, so the generated crate fails with E0433. Free-form body parameters already avoid this because updateRequestBodyForObject marks them primitive; give non-body free-form parameters the same treatment. Free-form schemas with additionalProperties stay containers (HashMap) and keep their JSON serialization. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CxDNCjqJycKTfzVWg2SeTJ
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.
A free-form object parameter —
type: objectwith no properties — is typedOption<models::serde_json::Value>in every generated api module, butmodelsre-exports noserde_json, so the crate fails to compile with oneE0433per operation that uses one:Free-form body parameters are typed
serde_json::Valueand compile fine; only query, path,and header parameters are affected. All four
rustclient libraries (reqwest,reqwest-trait,hyper,hyper0x) share the bug.The cause
The api templates qualify a parameter's type with
models::unless it is a string, uuid,primitive, or container —
rust/reqwest/api.mustacheand the same pattern in the other threelibraries:
A free-form object maps to
serde_json::Value(typeMapping.put("object", "serde_json::Value")),which lives outside
models. Body parameters escape becauseDefaultCodegen.updateRequestBodyForObjectmarks free-form bodiesisPrimitiveType = true,while
fromParametersets onlyisFreeFormObject— so the prefix lands on non-body parameters.The fix
RustClientCodegen.postProcessOperationsWithModelsnow marks free-form, non-containerparameters as primitive — the treatment free-form bodies already get — right next to the
existing
isAnyTypespecial case. One codegen change covers all four libraries' templates.Non-container matters: a free-form schema with
additionalPropertiesis typedHashMap<String, …>, is already exempt from the prefix as a container, and must keep itsserde_json::to_stringquery serialization sinceHashMaphas noDisplay.Wire behavior is unchanged: the query serialization branch for these parameters is chosen by
isObject/isMap/isDeepObject, notisPrimitiveType, and the required-parameter pathalways used
.to_string()(forserde_json::Value,Displayis its JSON serialization).Tests
RustClientCodegenTest#testFreeFormObjectQueryParam, generating from the new fixture3_0/rust/free-form-object-query-param.yaml, locks in:filter: Option<serde_json::Value>and nomodels::serde_jsonanywhere;type: objectwith typedadditionalPropertiesstayingHashMap<String, String>;additionalProperties: true(free-form and a map) stayingHashMap<String, serde_json::Value>withserde_json::to_stringserialization.It fails without the
main/change.Verified by compiling generated clients
Clients generated from a spec with optional, required, and map-typed object query parameters:
cargo buildTwo adjacent breakages exist identically on master and in v7.15.0, i.e. before this change,
and are left out of scope:
reqwest-traitcalls.to_string()on map-typed queryparameters (which this PR does not touch), and the exploded
style: deepObjectfree-formbranch iterates a
serde_json::Value(.len()/.iter()), which does not compile either way.PR checklist
./bin/generate-samples.sh ./bin/configs/rust-*regenerated all 39 rust configs with zero diffs (no sample spec has a free-form object
parameter outside a body);
./bin/utils/export_docs_generators.shproduced no diff.Generated with Claude Code
Summary by cubic
Fixes generated Rust clients failing to compile when an operation uses a free-form object query, path, or header parameter. These were typed
models::serde_json::Value, which doesn't exist; they're nowserde_json::Value, matching free-form body parameters.reqwest,reqwest-trait,hyper,hyper0x).additionalPropertiesstayHashMap-typed and keep their existing query serialization; no wire behavior changes.additionalProperties: truefree-form object query parameters.Written for commit 1a9f875. Summary will update on new commits.