juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.48k stars 197 forks source link

no_recursion with HasMap not working #1166

Closed fospitia closed 3 weeks ago

fospitia commented 3 weeks ago

Hi.

Next code fails with stack overflow

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

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

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

Without the Map(HashMap<String, Recursion>) line work.

And if you add it, the macro gives the following error

    #[schema(no_recursion)]
    Map(HashMap<String, Recursion>),
NoRecursion does not support `ToTokens`

Thanks

juhaku commented 3 weeks ago

Oh, that is a bug indeed,

   #[schema(no_recursion)]
    Map(HashMap<String, Recursion>),

The above should be possible.