Skip to content

Commit

Permalink
fix toJson output issue
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmossas committed Jun 14, 2024
1 parent 13b0639 commit febd724
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion languages/rust/rust-codegen-reference/src/example_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,8 @@ impl ArriModel for RecursiveObject {

fn to_query_params_string(&self) -> String {
let mut _query_parts_: Vec<String> = 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("&")
}
}
21 changes: 17 additions & 4 deletions languages/rust/rust-codegen/src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_")};`,
);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit febd724

Please sign in to comment.