Skip to content

schema_for! causes a stack overflow when using a recursively defined key in a BTreeMap #510

@BergLucas

Description

@BergLucas

Hi,

I called schema_for! on a type where I accidentally used a recursively defined type as a key in a BTreeMap, which is not allowed in JSON Schemas because all keys must be strings. However, it took me quite a while to figure out where the problem was coming from because I was getting a stack overflow. It's not a major bug, but I'm reporting it so you're aware of it.

Minimal reproducible example

use std::collections::BTreeMap;
use schemars::{JsonSchema, schema_for};

#[derive(JsonSchema, Ord, PartialOrd, Eq, PartialEq)]
struct Test(BTreeMap<Test, u32>);

fn main() {
    schema_for!(Test);
}

Error

thread 'main' (59210) has overflowed its stack
fatal runtime error: stack overflow, aborting

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions