From a4185a5665bb4cca9dda18cd1b23fc80d3542a12 Mon Sep 17 00:00:00 2001 From: Dominic Date: Tue, 1 Oct 2019 18:03:44 +0200 Subject: [PATCH] fix bug: required is now properly populated --- src/helper.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/helper.rs b/src/helper.rs index 0a5fb1e..d4c7fcc 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -40,17 +40,26 @@ macro_rules! rest_struct { $( { let mut schema = <$field_ty>::to_schema(); + + if schema.nullable + { + schema.nullable = false; + schema.name = schema.name.map(|name| + if name.ends_with("OrNull") { + name[..(name.len()-6)].to_string() + } else { name }); + } + else + { + required.push(stringify!($field_id).to_string()); + } + if let Some(name) = schema.name.clone() { properties.insert( stringify!($field_id).to_string(), ReferenceOr::Reference { reference: format!("#/components/schemas/{}", name) } ); - if schema.nullable - { - required.push(stringify!($field_id).to_string()); - schema.nullable = false; - } dependencies.insert(name, schema); } else