From c4a7d4f6d3ffa848384211f0149cd068b8e898f6 Mon Sep 17 00:00:00 2001 From: Marek Goc Date: Fri, 13 Jan 2023 13:29:14 +0100 Subject: [PATCH] model_extra_derives to be also added to coresponding enums --- sea-orm-codegen/src/entity/active_enum.rs | 9 +++++---- sea-orm-codegen/src/entity/writer.rs | 13 +++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/sea-orm-codegen/src/entity/active_enum.rs b/sea-orm-codegen/src/entity/active_enum.rs index de791752e..f86979651 100644 --- a/sea-orm-codegen/src/entity/active_enum.rs +++ b/sea-orm-codegen/src/entity/active_enum.rs @@ -12,7 +12,7 @@ pub struct ActiveEnum { } impl ActiveEnum { - pub fn impl_active_enum(&self, with_serde: &WithSerde, with_copy_enums: bool) -> TokenStream { + pub fn impl_active_enum(&self, with_serde: &WithSerde, with_copy_enums: bool, mut extra_derive: TokenStream) -> TokenStream { let enum_name = &self.enum_name.to_string(); let enum_iden = format_ident!("{}", enum_name.to_camel_case()); let values: Vec = self.values.iter().map(|v| v.to_string()).collect(); @@ -24,7 +24,8 @@ impl ActiveEnum { } }); - let extra_derive = with_serde.extra_derive(); + extra_derive.extend(with_serde.extra_derive()); + let copy_derive = if with_copy_enums { quote! { , Copy } } else { @@ -72,7 +73,7 @@ mod tests { .map(|variant| Alias::new(variant).into_iden()) .collect(), } - .impl_active_enum(&WithSerde::None, true) + .impl_active_enum(&WithSerde::None, true, quote!("")) .to_string(), quote!( #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy)] @@ -105,4 +106,4 @@ mod tests { .to_string() ) } -} +} \ No newline at end of file diff --git a/sea-orm-codegen/src/entity/writer.rs b/sea-orm-codegen/src/entity/writer.rs index 21568380b..21cb45660 100644 --- a/sea-orm-codegen/src/entity/writer.rs +++ b/sea-orm-codegen/src/entity/writer.rs @@ -167,7 +167,7 @@ impl EntityWriter { files.push(self.write_prelude()); if !self.enums.is_empty() { files.push( - self.write_sea_orm_active_enums(&context.with_serde, context.with_copy_enums), + self.write_sea_orm_active_enums(context), ); } WriterOutput { files } @@ -277,17 +277,18 @@ impl EntityWriter { pub fn write_sea_orm_active_enums( &self, - with_serde: &WithSerde, - with_copy_enums: bool, + context: &EntityWriterContext ) -> OutputFile { let mut lines = Vec::new(); Self::write_doc_comment(&mut lines); - Self::write(&mut lines, vec![Self::gen_import(with_serde)]); + Self::write(&mut lines, vec![Self::gen_import(&context.with_serde)]); lines.push("".to_owned()); + + let code_blocks = self .enums .values() - .map(|active_enum| active_enum.impl_active_enum(with_serde, with_copy_enums)) + .map(|active_enum| active_enum.impl_active_enum(&context.with_serde, context.with_copy_enums, context.model_extra_derives.clone())) .collect(); Self::write(&mut lines, code_blocks); OutputFile { @@ -1957,4 +1958,4 @@ mod tests { Ok(expected.to_string()) } -} +} \ No newline at end of file