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

Schemars can't deal with TOML files #274

Open
alper opened this issue Mar 20, 2024 · 2 comments
Open

Schemars can't deal with TOML files #274

alper opened this issue Mar 20, 2024 · 2 comments

Comments

@alper
Copy link

alper commented Mar 20, 2024

I have a struct field with a type like this: toml::map::Map<String, Value>

Schemars can't deal with this. What's a good way to fix this?

@alper
Copy link
Author

alper commented Mar 21, 2024

I'm trying to follow this but it looks like it's something of a rabbit hole?
https://graham.cool/schemars/examples/5-remote_derive/

@GREsau
Copy link
Owner

GREsau commented Mar 23, 2024

The easiest way to achieve this would be do decorate those fields with #[serde(with = "T")] where T has an equivalent schema, e.g. BTreeMap

use std::collections::BTreeMap;

#[derive(JsonSchema)]
pub struct MyType {
    #[serde(with = "BTreeMap::<String, Value>")]
    my_map: toml::map::Map<String, Value>,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants