diff --git a/languages/rust/rust-codegen-reference/src/example_client.rs b/languages/rust/rust-codegen-reference/src/example_client.rs index 0701e0a5..c956db43 100644 --- a/languages/rust/rust-codegen-reference/src/example_client.rs +++ b/languages/rust/rust-codegen-reference/src/example_client.rs @@ -1890,7 +1890,8 @@ impl ArriModel for RecursiveObject { fn to_query_params_string(&self) -> String { let mut _query_parts_: Vec = Vec::new(); - println!("[WARNING] cannot serialize nested objects to query params. Skipping field at /RecursiveObject/object."); + println!("[WARNING] cannot serialize nested objects to query params. Skipping field at /RecursiveObject/left."); + println!("[WARNING] cannot serialize nested objects to query params. Skipping field at /RecursiveObject/right."); _query_parts_.join("&") } } diff --git a/languages/rust/rust-codegen/src/object.ts b/languages/rust/rust-codegen/src/object.ts index 333d67ba..757209cd 100644 --- a/languages/rust/rust-codegen/src/object.ts +++ b/languages/rust/rust-codegen/src/object.ts @@ -95,9 +95,22 @@ export default function rustObjectFromSchema( toJsonParts.push(`\t\t_json_output_.push_str(",\\"${key}\\":");`); } const leading = isSchemaFormElements(prop) ? "" : "&"; - toJsonParts.push( - `\t\t${innerType.toJsonTemplate(`${leading}self.${fieldName}`, "_json_output_")};`, - ); + if (innerType.isNullable) { + const innerKey = validRustIdentifier(key); + toJsonParts.push(`\t\tmatch ${leading}self.${fieldName} { + Some(${innerKey}_val) => { + ${innerType.toJsonTemplate(`${innerKey}_val`, "_json_output_")}; + } + _ => { + _json_output_.push_str("null"); + } + };`); + } else { + toJsonParts.push( + `\t\t${innerType.toJsonTemplate(`${leading}self.${fieldName}`, "_json_output_")};`, + ); + } + toQueryParamParams.push( `\t\t${innerType.toQueryStringTemplate(`&self.${fieldName}`, key, "_query_parts_")};`, ); @@ -137,7 +150,7 @@ export default function rustObjectFromSchema( };`); } else { const innerKey = validRustIdentifier(`${key}_val`); - toJsonParts.push(`match &self.${fieldName} { + toJsonParts.push(`\t\tmatch &self.${fieldName} { Some(${innerKey}) => { ${ i !== 0