[rust] fix: free-form object query parameters reference a nonexistent models::serde_json
A free-form object parameter (type: object, no properties) is typed models::serde_json::Value in the generated api modules. models re-exports no serde_json, so the crate fails with one E0433 per operation. Free-form bodies are fine; query, path and header parameters are affected in all four rust client libraries.
parameters:
- in: query
name: filter
schema:
type: object
pub async fn list_things(configuration: &configuration::Configuration, filter: Option<models::serde_json::Value>, ...)
error[E0433]: failed to resolve: could not find `serde_json` in `models`
Cause
The templates prefix a parameter type with models:: unless it is a string, uuid, primitive or container. DefaultCodegen.updateRequestBodyForObject marks free-form bodies primitive, but fromParameter does not do the same for other parameters.
Fix
postProcessOperationsWithModels marks non-container free-form parameters primitive, next to the existing isAnyType case. Free-form maps (additionalProperties) are containers and keep their handling.
Only the parameter types change. The flag is set on allParams, which the signatures read, while the query/header serialization blocks iterate their own copies (queryParams etc.). The emitted serialization is therefore byte-identical to master; diffed for hyper, reqwest and reqwest-trait.
Verification
RustClientCodegenTest#testFreeFormObjectQueryParamwith3_0/rust/free-form-object-query-param.yaml: a bare free-form object, a typed map and anadditionalProperties: truemap. It fails without the change.cargo buildof reqwest (sync and async), hyper and reqwest-trait clients is clean.- Samples: zero diffs across the rust configs.
Related
Two adjacent breakages that predate this change are fixed separately: map-typed .to_string() in #24896, exploded deepObject free-form in #24899.
PR checklist
- Read the contribution guidelines.
- Built the project and updated samples (
./bin/generate-samples.sh ./bin/configs/rust-*): zero diffs;./bin/utils/export_docs_generators.shproduced no diff. - Technical committee (Rust): @frol @farcaller @richardwhiuk @paladinzh @jacob-pro @dsteeley
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 now serde_json::Value, matching free-form body parameters.
- One codegen change covers all four Rust generators (
reqwest,reqwest-trait,hyper,hyper0x). - Free-form objects with
additionalPropertiesstayHashMap-typed and keep their existing query serialization; no wire behavior changes. - Adds a regression test run across all four libraries, covering free-form object query, path, and header parameters (plain, typed-map, and
additionalProperties: true).
Generated with Claude Code