From 44407ce7c3f54bb85633770e1adbc22cd1ba3d3b Mon Sep 17 00:00:00 2001 From: Shachar Langbeheim Date: Wed, 17 Sep 2025 15:32:25 +0300 Subject: [PATCH] Mark request body as not required if it is wrapped in an option. --- crates/aide/src/impls/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/aide/src/impls/mod.rs b/crates/aide/src/impls/mod.rs index bb0d0ba1..de3f4b5b 100644 --- a/crates/aide/src/impls/mod.rs +++ b/crates/aide/src/impls/mod.rs @@ -64,12 +64,20 @@ where T: OperationInput, { fn operation_input(ctx: &mut crate::generate::GenContext, operation: &mut Operation) { - // Make parameters proudced by T optional if T is wrapped in an Option. - // TODO: we should probably do this for the body as well. + // Make parameters & request body proudced by T optional if T is wrapped in an Option. let mut temp_op = Operation::default(); T::operation_input(ctx, &mut temp_op); T::operation_input(ctx, operation); + if let (Some(request_body), Some(_)) = (&mut operation.request_body, temp_op.request_body) { + request_body + .as_item_mut() + .iter_mut() + .for_each(|request_body| { + request_body.required = false; + }); + } + if temp_op.parameters.is_empty() { return; }