Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance no_recursion rule to apply also containers #1144

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

juhaku
Copy link
Owner

@juhaku juhaku commented Oct 16, 2024

This commit further enhances the no_recursion rule to also apply on named structs, enums and named field enum variants. When provided on these aforementioned levels it will apply to its fields / variants.

Example of the enhanced syntax.

 #[derive(ToSchema)]
 #[schema(no_recursion)]
 pub struct Tree {
     left: Box<Tree>,
     right: Box<Tree>,
 }

 #[derive(ToSchema)]
 #[schema(no_recursion)]
 pub enum TreeRecursion {
     Named { left: Box<TreeRecursion> },
     Unnamed(Box<TreeRecursion>),
     NoValue,
 }

 #[derive(ToSchema)]
 pub enum Recursion {
     #[schema(no_recursion)]
     Named {
         left: Box<Recursion>,
         right: Box<Recursion>,
     },
     #[schema(no_recursion)]
     Unnamed(Box<Recursion>),
     NoValue,
 }

Closes #1137

This commit further enhances the `no_recursion` rule to also apply on
named structs, enums and named field enum variants. When provided on
these aforementioned levels it will apply to its fields / variants.

Example of the enhanced syntax.
```rust
 #[derive(ToSchema)]
 #[schema(no_recursion)]
 pub struct Tree {
     left: Box<Tree>,
     right: Box<Tree>,
 }

 #[derive(ToSchema)]
 #[schema(no_recursion)]
 pub enum TreeRecursion {
     Named { left: Box<TreeRecursion> },
     Unnamed(Box<TreeRecursion>),
     NoValue,
 }

 #[derive(ToSchema)]
 pub enum Recursion {
     #[schema(no_recursion)]
     Named {
         left: Box<Recursion>,
         right: Box<Recursion>,
     },
     #[schema(no_recursion)]
     Unnamed(Box<Recursion>),
     NoValue,
 }
```

Closes #1137
@juhaku juhaku force-pushed the feature-enhance-no-recursion branch from d8703b7 to 506c3f2 Compare October 16, 2024 14:39
@juhaku juhaku merged commit 7e13bc9 into master Oct 16, 2024
22 checks passed
@juhaku juhaku deleted the feature-enhance-no-recursion branch October 16, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
Development

Successfully merging this pull request may close these issues.

1 participant