From 70b4081cde6504d1c1cdb05b9f3d34c841ece2f5 Mon Sep 17 00:00:00 2001 From: Cyborus Date: Tue, 16 Jan 2024 18:09:13 -0500 Subject: [PATCH] simple recursion prevention --- generator/src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/generator/src/main.rs b/generator/src/main.rs index 44911b9..cb34843 100644 --- a/generator/src/main.rs +++ b/generator/src/main.rs @@ -705,10 +705,11 @@ fn create_struct_for_definition( for (prop_name, prop_schema) in properties { let prop_ty = schema_ref_type_name(spec, prop_schema)?; let field_name = sanitize_ident(prop_name); - let field_ty = if required.contains(prop_name) { - prop_ty - } else { - format!("Option<{prop_ty}>") + let field_ty = match (!required.contains(prop_name), prop_ty == name) { + (false, false) => prop_ty, + (false, true) => format!("Box<{prop_ty}>"), + (true, false) => format!("Option<{prop_ty}>"), + (true, true) => format!("Option>"), }; fields.push_str(&field_name); fields.push_str(": ");