[rust] fix: exploded deepObject free-form query parameters do not compile - #24899
[rust] fix: exploded deepObject free-form query parameters do not compile#24899wiebren wants to merge 2 commits into
Conversation
…pile The exploded deepObject branch walks every map-flagged parameter with .len()/.iter() - fine for a HashMap-typed map (an object schema with declared additionalProperties), but a bare free-form object is a serde_json::Value, which has neither, so the generated crate did not compile. Split the branch on isContainer and walk the Value through as_object(): a non-object Value sends nothing, matching the parameter's declared object shape. The second of the two follow-ups promised in OpenAPITools#24866's body. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GcwZ1arjLZNpetHz2a3TJz
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Review pointed out the branch emitted unprefixed json-quoted pairs - not the deepObject wire format the style asks for - and that was true of the pre-existing HashMap iteration too. Both shapes (typed map and free-form serde_json::Value) now take crate::apis::parse_deep_object, the route the non-explode branch already uses: name[key]=value on the wire, one code path, and the Value shape compiles because to_value accepts both. The fixture gains a required-nullable parameter so all patched sites are exercised, and the test registers the generated tree for cleanup. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GcwZ1arjLZNpetHz2a3TJz
|
cubic's P1 was right, and it applied to the pre-existing HashMap branch as much as to the new one: neither emitted deepObject form. Rather than patch the free-form copy, both shapes now route through The two test remarks are addressed too: the fixture gains a required-nullable deepObject parameter so every patched site is exercised, and the generated tree is registered for cleanup ( Re-verified: |
A query parameter with
style: deepObject, explode: truewhose schema is a bare free-formobject (
type: object, noadditionalProperties) generates iteration code that cannotcompile: the exploded deepObject branch walks every map-flagged parameter with
.len()/.iter(), which exist on theHashMapa declared-additionalPropertiesschemaproduces but not on the
serde_json::Valuea bare free-form schema produces.This is the second of the two follow-ups promised in #24866's body ("the exploded
deepObjectfree-form branch iterates aserde_json::Value"); the first became #24896.The fix
The deepObject
{{#isMap}}branch splits onisContainer— exactly the flag that separatesthe two typings (#24866 uses the same distinction). The
HashMapshape keeps its directiteration; the
serde_json::Valueshape walks the value throughas_object():A non-object
Valuesends nothing, matching the parameter's declared object shape. Fourtemplate sites: the nullable-required and optional paths in reqwest and reqwest-trait
(hyper has no deepObject-explode branch).
Tests
RustClientCodegenTest#testDeepObjectFreeFormQueryParamCompilesgenerates the new3_0/rust/deep-object-free-form-query-param.yamlfixture (one deepObject parameter of eachshape) for both libraries and asserts the
as_object()walk next to the direct mapiteration. Fails without the template change (verified by stashing it).
Verified by
cargo buildof clients generated from the fixture for both libraries: cleanwith this change. Note the bare free-form parameter's type additionally needs #24866
(
models::serde_json::Valuetoday); the two changes touch different lines and compose —the builds were verified with both applied.
PR checklist
./bin/generate-samples.sh ./bin/configs/rust-*):zero diffs - no sample spec has an exploded deepObject free-form parameter.
Generated with Claude Code
Summary by cubic
Fixes Rust codegen for exploded deepObject query parameters with bare free-form object schemas, which previously generated uncompilable iteration code. Both
reqwestandreqwest-traitnow route exploded deepObject maps throughparse_deep_object, which also changes typed maps to emit thename[key]=valuewire format instead of json-quoted pairs.Bug Fixes
parse_deep_objectto all four exploded deepObject map sites across both templates.Written for commit 3590759. Summary will update on new commits.