[rust] fix: exploded deepObject free-form query parameters do not compile

Merged
WI
2mo ago
+69-20

A query parameter with style: deepObject, explode: true whose schema is a bare free-form
object (type: object, no additionalProperties) generates iteration code that cannot
compile: the exploded deepObject branch walks every map-flagged parameter with
.len()/.iter(), which exist on the HashMap a declared-additionalProperties schema
produces but not on the serde_json::Value a bare free-form schema produces.

This is the second of the two follow-ups promised in #24866's body ("the exploded
deepObject free-form branch iterates a serde_json::Value"); the first became #24896.

The fix

The deepObject {{#isMap}} branch splits on isContainer — exactly the flag that separates
the two typings (#24866 uses the same distinction). The HashMap shape keeps its direct
iteration; the serde_json::Value shape walks the value through as_object():

if let Some(object) = param_value.as_object() {
    let mut query_params = Vec::with_capacity(object.len());
    for (key, value) in object.iter() {
        query_params.push((key.to_string(), serde_json::to_string(value)?));
    }
    req_builder = req_builder.query(&query_params);
}

A non-object Value sends nothing, matching the parameter's declared object shape. Four
template sites: the nullable-required and optional paths in reqwest and reqwest-trait
(hyper has no deepObject-explode branch).

Tests

RustClientCodegenTest#testDeepObjectFreeFormQueryParamCompiles generates the new
3_0/rust/deep-object-free-form-query-param.yaml fixture (one deepObject parameter of each
shape) for both libraries and asserts the as_object() walk next to the direct map
iteration. Fails without the template change (verified by stashing it).

Verified by cargo build of clients generated from the fixture for both libraries: clean
with this change. Note the bare free-form parameter's type additionally needs #24866
(models::serde_json::Value today); the two changes touch different lines and compose —
the builds were verified with both applied.

PR checklist

  • Read the contribution guidelines.
  • Built the project and updated samples (./bin/generate-samples.sh ./bin/configs/rust-*):
    zero diffs - no sample spec has an exploded deepObject free-form parameter.
  • Technical committee (Rust): @frol @farcaller @richardwhiuk @paladinzh @jacob-pro @dsteeley

Summary by cubic

Fixes Rust codegen for exploded deepObject query parameters with bare free-form object schemas, which previously generated uncompilable iteration code. Both reqwest and reqwest-trait now route exploded deepObject maps through parse_deep_object, which also changes typed maps to emit the name[key]=value wire format instead of json-quoted pairs.

Bug Fixes

  • Applies parse_deep_object to all four exploded deepObject map sites across both templates.
  • Adds a test fixture and generator test covering optional typed maps, optional free-form objects, and required-nullable maps in both libraries.

Generated with Claude Code