Closed CobaltCause closed 1 year ago
use doku::Document; use serde::Deserialize; #[derive(Deserialize, Debug, Document)] struct Config { foo: Foo, } #[derive(Deserialize, Debug, Document)] struct Foo { #[serde(flatten)] bar: Bar, } #[derive(Deserialize, Debug, Document)] #[serde(untagged)] enum Bar { Baz { wat: String, }, Qux { huh: String, wut: String, }, } fn main() { println!("{}", doku::to_json::<Config>()); }
{ "foo": { "wat": "string" // or "huh": "string", "wut": "string" } }
use doku::Document; use serde::Deserialize; #[derive(Deserialize, Debug, Document)] struct Config { foo: Foo, } #[derive(Deserialize, Debug, Document)] struct Foo { #[serde(flatten)] bar: Bar, } #[derive(Deserialize, Debug, Document)] #[serde(untagged)] enum Bar { Baz { wat: String, }, Qux(Qux), } #[derive(Deserialize, Debug, Document)] struct Qux { huh: String, wut: String, } fn main() { println!("{}", doku::to_json::<Config>()); }
{ "foo": { "wat": "string" // or { "huh": "string", "wut": "string" } } }
Note the extra brackets around the huh and wut fields. Is this expected behavior? It seems like a bug because serde handles these two cases identically.
huh
wut
Oh, nice catch - I'll take a look tomorrow!
Hi, I've just published v0.21.1 with this change - if you do cargo update -p doku, you should get the fix.
cargo update -p doku
If anything else looks off, lemme know 🙂
Enum struct variant
Code
Output
Enum tuple variant of struct
Code
Output
Note the extra brackets around the
huh
andwut
fields. Is this expected behavior? It seems like a bug because serde handles these two cases identically.