Skip to content

Commit

Permalink
Cont. Added support for using sea-orm with #[deny(missing_docs)] (#1531)
Browse files Browse the repository at this point in the history
* Added support for using sea-orm with #[deny(missing_docs)] (#1522)

* feat(macros): Added documentation tags for generated entities

* chore: Added deny(missing_docs) attribute to basic example

* chore: Fix clippy errors

* ci: test missing docs of derive macros generated types

* Try missing docs (CI should fail)

* Revert "Try missing docs (CI should fail)"

This reverts commit 83356bf.

---------

Co-authored-by: Lewin Probst, M.Sc <[email protected]>
  • Loading branch information
billy1624 and emirror-de authored Mar 10, 2023
1 parent 27e061c commit 4f8ad56
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 13 deletions.
7 changes: 7 additions & 0 deletions examples/basic/src/example_cake.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
//! The `cake` entity.

use sea_orm::entity::prelude::*;

/// Cake entity
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
#[sea_orm(table_name = "cake")]
pub struct Model {
#[sea_orm(primary_key)]
/// id field
pub id: i32,
/// name field
pub name: String,
}

/// Cake relation
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
/// Fruit relation
Fruit,
}

Expand Down
15 changes: 15 additions & 0 deletions examples/basic/src/example_cake_filling.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! The `cake_filling` entity.

use sea_orm::entity::prelude::*;

/// CakeFilling entity
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;

Expand All @@ -9,21 +12,30 @@ impl EntityName for Entity {
}
}

/// CakeFilling model
#[derive(Clone, Debug, PartialEq, Eq, DeriveModel, DeriveActiveModel)]
pub struct Model {
/// cake_id field
pub cake_id: i32,
/// filling_id field
pub filling_id: i32,
}

/// CakeFilling column
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
/// CakeId column
CakeId,
/// FillingId column
FillingId,
}

/// CakeFilling primary key
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
/// CakeId primary key
CakeId,
/// FillingId primary key
FillingId,
}

Expand All @@ -35,9 +47,12 @@ impl PrimaryKeyTrait for PrimaryKey {
}
}

/// CakeFilling relation
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
/// Cake relation
Cake,
/// Filling relation
Filling,
}

Expand Down
12 changes: 12 additions & 0 deletions examples/basic/src/example_filling.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! The `filling` entity.

use sea_orm::entity::prelude::*;

/// Filling entity
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;

Expand All @@ -9,20 +12,28 @@ impl EntityName for Entity {
}
}

/// Filling model
#[derive(Clone, Debug, PartialEq, Eq, DeriveModel, DeriveActiveModel)]
pub struct Model {
/// id field
pub id: i32,
/// name field
pub name: String,
}

/// Filling column
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
/// Id column
Id,
/// Name column
Name,
}

/// Filling primary key
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
/// Id primary key
Id,
}

Expand All @@ -34,6 +45,7 @@ impl PrimaryKeyTrait for PrimaryKey {
}
}

/// Filling relation
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {}

Expand Down
15 changes: 15 additions & 0 deletions examples/basic/src/example_fruit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! The `fruit` entity.

use sea_orm::entity::prelude::*;

/// Fruit entity
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
pub struct Entity;

Expand All @@ -9,22 +12,32 @@ impl EntityName for Entity {
}
}

/// Fruit model
#[derive(Clone, Debug, PartialEq, Eq, DeriveModel, DeriveActiveModel)]
pub struct Model {
/// id field
pub id: i32,
/// name field
pub name: String,
/// cake_id field
pub cake_id: Option<i32>,
}

/// Fruit column
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
pub enum Column {
/// Id column
Id,
/// Name column
Name,
/// CakeId column
CakeId,
}

/// Fruit primary key
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
/// Id primary key
Id,
}

Expand All @@ -36,8 +49,10 @@ impl PrimaryKeyTrait for PrimaryKey {
}
}

/// Fruit relation
#[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation {
/// Cake relation
Cake,
}

Expand Down
13 changes: 9 additions & 4 deletions examples/basic/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
//! Basic sea-orm example.

#![deny(missing_docs)]

use sea_orm::Database;

mod entities;
mod example_cake;
mod example_cake_filling;
mod example_filling;
mod example_fruit;
pub mod example_cake;
pub mod example_cake_filling;
pub mod example_filling;
pub mod example_fruit;
mod operation;
pub mod sea_orm_active_enums;
mod select;

use entities::*;
Expand Down
15 changes: 15 additions & 0 deletions examples/basic/src/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! SeaORM's active enums.

use sea_orm::entity::prelude::*;

/// Tea active enum
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "tea")]
pub enum Tea {
/// EverydayTea variant
#[sea_orm(string_value = "EverydayTea")]
EverydayTea,
/// BreakfastTea variant
#[sea_orm(string_value = "BreakfastTea")]
BreakfastTea,
}
4 changes: 4 additions & 0 deletions sea-orm-macros/src/derives/active_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ impl ActiveEnum {
.collect();

quote!(
#[doc = " Generated by sea-orm-macros"]
#[derive(Debug, Clone, PartialEq, Eq, sea_orm::EnumIter)]
pub enum #enum_variant_iden {
#(
#[doc = " Generated by sea-orm-macros"]
#enum_variants,
)*
}
Expand All @@ -276,6 +278,7 @@ impl ActiveEnum {

#[automatically_derived]
impl #ident {
#[doc = " Generated by sea-orm-macros"]
pub fn iden_values() -> Vec<sea_orm::sea_query::DynIden> {
<#enum_variant_iden as sea_orm::strum::IntoEnumIterator>::iter()
.map(|v| sea_orm::sea_query::SeaRc::new(v) as sea_orm::sea_query::DynIden)
Expand All @@ -297,6 +300,7 @@ impl ActiveEnum {
};

quote!(
#[doc = " Generated by sea-orm-macros"]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct #enum_name_iden;

Expand Down
16 changes: 8 additions & 8 deletions sea-orm-macros/src/derives/active_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ pub fn expand_derive_active_model(ident: Ident, data: Data) -> syn::Result<Token
fn derive_active_model(all_fields: IntoIter<Field>) -> syn::Result<TokenStream> {
let fields = all_fields.filter(field_not_ignored);

let field: Vec<Ident> = fields.clone().into_iter().map(format_field_ident).collect();
let field: Vec<Ident> = fields.clone().map(format_field_ident).collect();

let name: Vec<Ident> = fields
.clone()
.into_iter()
.map(|field| {
let ident = field.ident.as_ref().unwrap().to_string();
let ident = trim_starting_raw_identifier(ident).to_camel_case();
Expand Down Expand Up @@ -78,9 +77,14 @@ fn derive_active_model(all_fields: IntoIter<Field>) -> syn::Result<TokenStream>
let ty: Vec<Type> = fields.into_iter().map(|Field { ty, .. }| ty).collect();

Ok(quote!(
#[doc = " Generated by sea-orm-macros"]
#[derive(Clone, Debug, PartialEq)]
pub struct ActiveModel {
#(pub #field: sea_orm::ActiveValue<#ty>),*

#(
#[doc = " Generated by sea-orm-macros"]
pub #field: sea_orm::ActiveValue<#ty>
),*
}

#[automatically_derived]
Expand Down Expand Up @@ -172,11 +176,7 @@ fn derive_into_model(model_fields: IntoIter<Field>) -> syn::Result<TokenStream>
.into_iter()
.map(format_field_ident)
.collect();
let model_field: Vec<Ident> = model_fields
.clone()
.into_iter()
.map(format_field_ident)
.collect();
let model_field: Vec<Ident> = model_fields.clone().map(format_field_ident).collect();

let ignore_attr: Vec<bool> = model_fields
.map(|field| !field_not_ignored(&field))
Expand Down
9 changes: 8 additions & 1 deletion sea-orm-macros/src/derives/entity_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
.as_ref()
.map(|table_name| {
quote! {
#[doc = " Generated by sea-orm-macros"]
#[derive(Copy, Clone, Default, Debug, sea_orm::prelude::DeriveEntity)]
pub struct Entity;

Expand Down Expand Up @@ -72,6 +73,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
if let Some(table_name) = table_name {
let table_field_name = Ident::new("Table", Span::call_site());
columns_enum.push(quote! {
#[doc = " Generated by sea-orm-macros"]
#[sea_orm(table_name=#table_name)]
#[strum(disabled)]
#table_field_name
Expand Down Expand Up @@ -226,8 +228,11 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
let variant_attrs = match &column_name {
Some(column_name) => quote! {
#[sea_orm(column_name = #column_name)]
#[doc = " Generated by sea-orm-macros"]
},
None => quote! {
#[doc = " Generated by sea-orm-macros"]
},
None => quote! {},
};

if ignore {
Expand Down Expand Up @@ -360,6 +365,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
quote! { (#primary_key_types) }
};
quote! {
#[doc = " Generated by sea-orm-macros"]
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
pub enum PrimaryKey {
#primary_keys
Expand All @@ -377,6 +383,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
};

Ok(quote! {
#[doc = " Generated by sea-orm-macros"]
#[derive(Copy, Clone, Debug, sea_orm::prelude::EnumIter, sea_orm::prelude::DeriveColumn)]
pub enum Column {
#columns_enum
Expand Down

0 comments on commit 4f8ad56

Please sign in to comment.