From 73119b0be5607178f809deaad446e68d81acc91a Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Wed, 4 Oct 2023 18:47:29 +0200 Subject: [PATCH] remove empty base types --- .../autorust/codegen/src/codegen_models.rs | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/services/autorust/codegen/src/codegen_models.rs b/services/autorust/codegen/src/codegen_models.rs index 2bca4fd490..9c8d045770 100644 --- a/services/autorust/codegen/src/codegen_models.rs +++ b/services/autorust/codegen/src/codegen_models.rs @@ -490,15 +490,17 @@ pub fn create_models(cg: &mut CodeGen) -> Result { let tag_property = schema.properties.iter().find(|property| property.name() == tag); let tag_property_description = tag_property.and_then(|property| property.schema().schema.common.description.clone()); schema.properties.retain(|property| property.name() != tag); + if !schema.properties.is_empty() { + models.push(ModelCode::Struct(create_struct( + cg, + &schema, + schema_name, + pageable_response_names.get(&pageable_name), + HashSet::new(), + )?)); + } // create the union type with the discriminator - models.push(ModelCode::Struct(create_struct( - cg, - &schema, - schema_name, - pageable_response_names.get(&pageable_name), - HashSet::new(), - )?)); models.push(ModelCode::Union(UnionCode::from_schema( tag, schema_name, @@ -900,6 +902,14 @@ fn create_struct( needs_boxing.insert(struct_name.to_camel_case_ident()?.to_string()); for schema in schema.all_of() { + // skip empty base types + let mut properties_len = schema.properties().len(); + if schema.discriminator().is_some() { + properties_len = properties_len.saturating_sub(1); + } + if properties_len < 1 { + continue; + } let schema_name = schema.name()?; let mut type_name = TypeNameCode::from(schema_name.to_camel_case_ident()?); type_name.union(false);