GREsau / schemars

Generate JSON Schema documents from Rust code
https://graham.cool/schemars/
MIT License
791 stars 220 forks source link

Schemars can't deal with TOML files #274

Open alper opened 5 months ago

alper commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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>,
}