Skip to content

Commit

Permalink
remove empty base types
Browse files Browse the repository at this point in the history
  • Loading branch information
cataggar committed Oct 4, 2023
1 parent b9684c0 commit 73119b0
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions services/autorust/codegen/src/codegen_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,15 +490,17 @@ pub fn create_models(cg: &mut CodeGen) -> Result<ModelsCode> {
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,
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 73119b0

Please sign in to comment.